Reset A Select Element
how to make the first option selected? I tried this but doesnt work: selectElement.options[0].selected=true; it gives me this error: Uncaught TypeError: Cannot read propert
Solution 1:
Try this
document.getElementById('mySelect').selectedIndex = 0;
Solution 2:
Try this (See the demo)
HTML
<selectid="selectElement"><option>First</option><optionselected>Second</option></select>
JavaScript
selectElement.options[0].selected="selected";
Or you can do selectElement.options[0].selected=true;
Hope this works for you.
Post a Comment for "Reset A Select Element"