The select box can be placed in web page by using following code.
<FORM name="formMain">
<SELECT name="selData">
<OPTION SELECTED value="data1">mydata1
<OPTION value="data2">mydata2
</SELECT>
</FORM>
The select box can be accessed from JavaScript as follows.
To get no. of items in the select box
document.formMain.selData.length
To find whether an option in select box is selected or not
document.formMain.selData.options[0].selected
To get the value attribute of first option
document.formMain.selData.options[0].value
To get the index of selected item in select box
document.formMain.selData.selectedIndex
To get the value of selected Item
document.formMain.selData.options[document.formMain.selData.selectedIndex].value
Note: JavaScript is case sensitive.
Labels: HTML , JavaScript
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment