I'm using following html to get the selected-by-default disabled option "Select a town" as a kind of placeholder.
<select name="town">
<option selected disabled value="xx">-- Select a town --</option>
<option value="1">Paris</option>
<option value="2">London</option>
<option value="3">Budapest</option>
</select>
Now I'd like to test if any option has been selected by the user, or if it's still empty.
I thought testing the select value using jquery ( $('select[name="town"]').val();
) would return the value "xx".
Instead of that, .val()
returns null.
I found no trace of this behaviour in the doc (http://api.jquery.com/val/).
Can I rely on .val()
returning null when a disabled option is selected? Is it documented anywhere?
Or do I have to check against both null and the actual value of the value
attribute ("xx" in the above example)?