Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change value of selectric drop down programmatically?

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?

like image 641
user1283776 Avatar asked Apr 05 '18 15:04

user1283776


1 Answers

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');
like image 169
Rory McCrossan Avatar answered Jan 02 '23 22:01

Rory McCrossan