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?
For purely html @isherwood has a great solution. For jQuery, give your select drop down an ID then select it with jQuery:
Then use this jQuery to clear the drop down on page load:
Or put it inside a function by itself:
accomplishes what you're looking for and it is easy to put this in functions that may get called on your page if you need to blank out the drop down without reloading the page.
You can try this snippet
It worked for me.
You can by setting
selectedIndex
to-1
using.prop
: http://jsfiddle.net/R9auG/.For older jQuery versions use
.attr
instead of.prop
: http://jsfiddle.net/R9auG/71/.You can't. They simply do not work that way. A drop down menu must have one of its options selected at all times.
You could (although I don't recommend it) watch for a change event and then use JS to delete the first option if it is blank.
Just use disabled and/or hidden attributes:
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.Here is a simple way to do it using plain JavaScript. This is the vanilla equivalent of the jQuery script posted by pimvdb. You can test it here.
.
Make sure the "id_here" matches in the form and in the JavaScript.