The following example will display three alert messages when you
change the selection of the combo box, the first alert message will
display the selected index of the list (starting from 0), the second
alert message will display the value of the value attribute of the selected option and the third alert will display the text of the selected option:
<html> <head> <script type='text/javascript'> function onchangeCombobox(obj) { var selectedIndex = obj.selectedIndex; // display the selected index starting from 0. alert('selected index=' + selectedIndex); // display the value of the value attribute. alert('selected value=' + obj.options[selectedIndex].value);
// display the text of the selected option. alert('selected text=' + obj.options[selectedIndex].text); } </script> </head> <body> <select onchange="javascript: onchangeCombobox(this);"> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option> </select> </body> </html>
|