rain13 Posted March 6, 2012 Share Posted March 6, 2012 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 More sharing options...
justsomeguy Posted March 6, 2012 Share Posted March 6, 2012 You need to loop through the list of options, check the value of each one to see if it has the right value, and select it. Link to comment Share on other sites More sharing options...
rain13 Posted March 6, 2012 Author Share Posted March 6, 2012 Thank you. Didn't see this option... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.