7

What is a good way to change the value of a Selectric drop down programmatically based on name? I know the value of the option I want to set as selected. I don't know the name or the index.

Here is my best attempt:

$('.store-availability').prop('selectedIndex', 3).selectric('refresh').change();

Since I don't know the index I would have to jQuery.Index() on the options first to find it or something like that. Is there a cleaner approach?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1283776
  • 19,640
  • 49
  • 136
  • 276

1 Answers1

6

If you know the value of the option you want to set you can use the setter of val(), then call refresh on the selectric instance, like this:

$('.store-availability').val(yourValueHere).change().selectric('refresh');
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339