So I have a drop down list
<select id="theSelectId"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select>
Here is what I would like
<select id="theSelectId"> <option value="" selected="selected"></option> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select>
Trying to add an empty parameter before this and set it to this, you must force the user to select a value from the source list, but it must be empty when they see the parameter that they should select.
Attempt but not working
// Add blank option var blankOption = {optVal : ''}; $.each(blankOption, function(optVal, text) { $('<option></option>').val(optVal).html(text).preprendTo('#theSelectId'); });
and I tried this but clears other values
$('#theSelectId option').prependTo('<option value=""></option>');
jquery select drop-down-menu
Phill Pafford Jul 01 '09 at 19:12 2009-07-01 19:12
source share