How To Read the Selected Items in a SELECT ControlLast reviewed: November 26, 1996Article ID: Q159757 |
The information in this article applies to:
SUMMARYThis article demonstrates how to read what items are selected in a SELECT control on a Web page using Visual Basic Script. Many reference documents indicate that a SELECT control has a VALUE property. However, this is not true. The SELECT control does not have a VALUE property, but the items in the OPTIONS collection of the SELECT control do. If you are not familiar with the SELECT control, it is similar to the ListBox control in Visual Basic.
MORE INFORMATIONIn order to read what item(s) are selected in a SELECT control, you must loop through the elements, and then check if the current element is selected. If it is selected, then you can perform an action. Use a text editor, such as Notepad.exe, to copy the following sample HTML code into an HTML file: ********* BEGIN Page1.HTM ******************* <HTML> <SCRIPT LANGUAGE="VBSCRIPT"> Sub ShowVals Dim SelStr For i = 0 to Form1.myselect.length - 1 If Form1.myselect.options(i).selected = 1 Then selstr = selstr & Form1.myselect.options(i).value & chr(10) End If Next MsgBox SelStr,,"Selected Item(s)" End Sub </SCRIPT> <BODY> <FORM NAME="Form1"> <SELECT MULTIPLE NAME="MySelect"> <OPTION VALUE="10">Option 1 (10) <OPTION VALUE="20">Option 2 (20) <OPTION VALUE="30">Option 3 (30) </SELECT> <BR> <INPUT TYPE=BUTTON onClick="ShowVals()" VALUE="Show Value(s)"> </FORM> </BODY></HTML> ********* BEGIN End.HTM *******************
Program Flow
REFERENCESFor additional information, visit the Microsoft Site Builder Workshop at http://www.microsoft.com/workshop.
|
KBCategory: kbprg kbhowto
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |