I have the following HTML code used to create on a page:
<select>
<option value="" selected>test</option>
<option value="test2">test2</option>
</select>
But when looking at the HTML in Google Chrome's DOM inspector it looks like this:
<select>
<option value selected>test</option>
<option value="test2">test2</option>
</select>
See the difference? For the first <option>...</option>, value="" is turned into just value. The value, when set to the empty string is simply discarded. Is there any way to set the value of an option tag to the empty string? I need this because I'm pulling elements out of a database to create a <select> menu. Each <option> will have it's value set to value of a database element and some of those elements have the empty string as their value.
It is just Google Chrome's DOM inspector's notation (removes '=""' from attributes). If you inspect it with FireBug or simply view the source then you will see it is OK.
Your sample code produces this in Google Chrome:

And this is the result in FireFox:

So don't worry about that.
bob
as Hanky said you can use
selected = "selected" or ""
so the code will be :
<select>
<option value="" selected="selected">test</option>
<option value="test2">test2</option>
or
<select>
<option value="" selected="">test</option>
<option value="test2">test2</option>
Checking this article may help : W3 option language reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With