'How to prevent the select tag to auto select the first option?
I want to add a floating placeholder for the select tag. But the select tag is choosing the fist option by default. I don't want to put an extra option without the value in the list.
Solution 1:[1]
Use this code:
<select name="tagging">
<option selected="true" style='display: none'></option>
<option value="Option A" >Option A</option>
<option value="Option B" >Option B</option>
<option value="Option C">Option C</option>
</select>
EDIT: Now the first option is selected but not visible.
Solution 2:[2]
<select>
<option hidden>Placeholder</option>
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
</select>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Luis Rodrigues |