Forum Discussion
Former Member
5 years agoI just stumbled across this question, and here's what works in Firefox and Chrome (at least):
<style>
select:invalid { color: gray; }
</style>
<form>
<select required>
<option value="" disabled selected hidden>Please Choose...</option>
<option value="0">Open when powered (most valves do this)</option>
<option value="1">Closed when powered, auto-opens when power is cut</option>
</select>
</form>
Run code snippet
Expand snippet
The Disabled option stops the <option>
being selected with both mouse and keyboard, whereas just using 'display:none'
allows the user to still select via the keyboard arrows. The 'display:none'
style just makes the list box look 'nice'.
Note: Using an empty value
attribute on the "placeholder" option allows validation (required attribute) to work around having the "placeholder", so if the option isn't changed, but is required, the browser should prompt the user to choose an option from the list.
- donaldfitzgerald5 years agoIdeator I
As a workaround for the Internet Explorer browser, you can add the
place_holder
class again in case the first option is selected again.