Blank HTML SELECT without blank item in dropdown list

Nick Stavrogin picture Nick Stavrogin · Jun 3, 2011 · Viewed 183.7k times · Source

How implement subj?

when i write:

<form>
  <select>
     <option value="0">aaaa</option>
     <option value="1">bbbb</option>
  </select>
</form>

then default selected item is "aaaa"

when i write:

<form>
  <select>
     <option value=""></option>
     <option value="0">aaaa</option>
     <option value="1">bbbb</option>
  </select>
</form>

then default selected item is blank, but this blank item presents in drop down.

how i can implement SELECT tag with default blank value that hidden in dropdown list?

Answer

Eduardo picture Eduardo · Aug 28, 2013

Just use disabled and/or hidden attributes:

<option selected disabled hidden style='display: none' value=''></option>
  • selected makes this option the default one.
  • disabled makes this option unclickable.
  • style='display: none' makes this option not displayed in older browsers. See: Can I Use documentation for hidden attribute.
  • hidden makes this option to don't be displayed in the drop-down list.