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 property '0' of undefined
update
solved! by defining selectElement correctly.
Try this (See the demo)
HTML
JavaScript
Or you can do
selectElement.options[0].selected=true;Hope this works for you.