if select option blank, then select option 3

129 views Asked by At

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.

1

There are 1 answers

1
Rory McCrossan On

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.