0

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.

Kevin B
  • 94,570
  • 16
  • 163
  • 180
user1410949
  • 1
  • 1
  • 1
  • 2

1 Answers1

3

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.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • If you're using jQuery 1.7+, the event shortcuts (`click()`, `change()`, `keypress()`, etc.) all use `on()` behind the scenes anyway. – Rory McCrossan May 24 '12 at 21:56