Help a beginner! What is wrong with this VBScript code?

70 pts.
Tags:
Arrays
VBScript
Web development
Web forms
<html> <head> <%Dim ColorIndex(4),Colors(4),i %> </head> <body> <%ColorIndex(1)="Love":ColorIndex(2)="Jealous":ColorIndex(3)="Peace":ColorIndex(4)=+"Leading" Colors(1)="red":Colors(2)="yellow":Colors(3)="green":Colors(4)="blue"%> <form name ="myform"> <select name="mycolors" onchange ="GetIndex()"> <% for i=1 to 4 %> <option><%= Colors(i)%></option> <% Next %> </select> <script language ="vbscript"> sub getIndex() dim c c=myform.mycolors.selectedIndex msgbox "you selected "& "<%=Colors(c)%>" & " which means " & "<%=colorIndex(c)%>" 'c won't work here end sub </script></form> </body> </html>

Answer Wiki

Thanks. We'll let you know when a new response is added.

I’m not a vbScript expert, but here’s one way of doing it:

<html>
<head>
<script language=”vbscript”>
sub getIndex(c)
msgbox “you selected ” & Colors(c) & ” which means ” & colorIndex(c)
end sub
</script>
</head>
<body>
<script language=”vbscript”>
‘use base index of zero on arrays
Dim ColorIndex(3),Colors(3),i
ColorIndex(0)=”Love”
ColorIndex(1)=”Jealous”
ColorIndex(2)=”Peace”
ColorIndex(3)=”Leading”
Colors(0)=”red”
Colors(1)=”yellow”
Colors(2)=”green”
Colors(3)=”blue”
document.write(“<form name=””myform””>”)
document.write(“<select name=””mycolors”” onchange =””getIndex(myform.mycolors.SelectedIndex)””>”)
for i=0 to 3
document.write(“<option>”)
document.write(Colors(i))
document.write(“</option>”)
Next
document.write(“</select>”)
</script>
</form>
</body>
</html>

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    What problems are you having ? Are you getting errors ? what is the error message ?
    77,040 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: