How to select the first empty value option in the selection menu?

The following always selects the last option, even when I set the selected attribute, but I like the first option to be preselected.

 <select name="filter"> <option value="" selected>Make a choice</option> <option value="1">1</option> <option value="3">3</option> <option value="7">7</option> <option value="">all</option> </select> 

Can this be done?

+4
source share
2 answers
 <select name="filter"> <option value="" selected="selected">Make a choice</option> <option value="1">1</option> <option value="3">3</option> <option value="7">7</option> <option value="">all</option> </select> 

If my code modification does not work. Check out this article and make sure it doesn't work at http://www.beyondcoding.com/2008/12/16/option-selectedselected-not-working/

+13
source

correct implementation:

 <option value="1" selected>1</option> <option value="9">9</option> 
0
source

Source: https://habr.com/ru/post/1309107/


All Articles