Jump to content

How to select combo box item by value?


rain13

Recommended Posts

After trying various things i failed to select item from combo box. Thing's I've tried already: element.options[2].selected = trueelement.value = "2";element.options[element.selectedIndex].value = "2"; How can I select option with value="2" ?

  <script type="text/javascript">function test(){	var element = document.getElementById("test");	//element.options[2].selected = true;	element.value = "2";  	//element.options[element.selectedIndex].value = "2";	//element.selectedIndex = "2";} </script><select name="test" ><option value="1">abc</option><option value="2">def</option><option value="3">ghi</option></select> <script type="text/javascript">test();</script>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...