TheMonkeyMan
TheMonkeyMan

Reputation: 9152

Dropdown List Option with Default Value that is not in the list

I am writing to ask is it possible to have a drop down list with a value pre-populated that is not in the actual list.

Say I have a system x that has a value y. and they can only ever choose on the new system value a or b. I would still like to display value y until they open the drop down at which point they loose it and it never comes back.

Upvotes: 3

Views: 2533

Answers (2)

Rafay
Rafay

Reputation: 31043

<select>
  <option value="" selected="selected">show girl</option>
  <option value="1">one</option>
</select>

on click remove the option

$("select").click(function(){
$("option[selected='selected']",this).remove();
});

UPDATE:

as @fbfcn suggested in the comments it would be more appropriate to use .one

$("select").one("click",function(e){
$("option[selected='selected']",this).remove();
});

Upvotes: 6

ParPar
ParPar

Reputation: 7569

You can put a div on the dropdownlist with your wanted default value, then hide it when the user selects a value from the selectlist.

but fitst try this:

$("#yourdropdownlist").val("defaultvalue"); 

Upvotes: 0

Related Questions