Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blank HTML SELECT without blank item in dropdown list

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?

like image 237
Nick Stavrogin Avatar asked Jun 03 '11 06:06

Nick Stavrogin


1 Answers

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.
like image 100
Eduardo Avatar answered Oct 06 '22 00:10

Eduardo