user1410949
user1410949

Reputation: 11

if select option blank, then select option 3

Thank you in advance for anyone who helps on this one.

We have a drop down with a blank option in the first .

<select id="Flags">
<option></option>
<option value="Corporate">Corporate.png</option>
<option value="Store2">Store2.png</option>
</select>

If the first blank option is selected, how can I remove it and select "Store2"?

If $('#Flags option[value=""]')
Then .remove();
and $('#Flags').val ("Store2")

Thank you very much in advance for any help.

Upvotes: 0

Views: 129

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337560

Try this:

$("#Flags").change(function() {
    if (!$(this).val()) 
        $(this).val("Store2");
});

It would be better to just have Store2 as the default with not blank option, as you may confuse your users if they choose the blank item, yet see 'Store2.png' selected.

Upvotes: 3

Related Questions