Reputation: 3260
I have a dropdown list that calls a vbscript.The issue is that when I try to get the value of the drop down list I get "object doesnt support property" or "method error".
<select onchange='callMe()' id='selectMe'>
<option value='1'>1</option>
<option value='3'>3</option>
<option value='2'>2</option>
</select>
<SCRIPT LANGUAGE="VBScript">
Sub callMe()
MsgBox(selectMe.value)
End Sub
</SCRIPT>
Can anyone point me in the correct direction please
Upvotes: 0
Views: 7356
Reputation: 346
you can do what Stephan Quan has posted as it does not matter where in page eg. head or body it is placed
in the following examples you would need to be in the body as it required for select element to be created prior to using
' if you just need to display
msgbox document.getElementById("selectMe").value
' if you need to do something with the value
dim somevariable
somevariable = document.getElementById("selectMe").value
in the second example somevariable would contain the value attribute from selected option
Upvotes: 1
Reputation: 25956
You can use W3Schools reference on the HTML DOM Select Object.
When using VBScript, you will get implicit events base on the object's id so you don't need to explicitly call them (i.e. selectMe_onchange). I've reworked your example as follows:
<html>
<head>
<title>VBScript Select event</title>
<script LANGUAGE="VBScript">
Sub selectMe_onchange
MsgBox selectMe.options(selectMe.selectedIndex).text
End Sub
</script>
</head>
<body>
<select id='selectMe'>
<option value='1'>1</option>
<option value='3'>3</option>
<option value='2'>2</option>
</select>
</body>
</html>
Upvotes: 1