0

Given the following jQuery plugin: http://selectric.js.org/index.html which replaces the functionality of that of a regular select box by using custom UL LI lists,

Based on the plugins documentation, I know that you can programmatically select an option value if you already know the index to select by using the following code:

 $('#idofselectbox').prop('selectedIndex', 3).selectric('refresh');

But they do not include a sample to be able to find and select an option value by a value.

For example,

Let's say i'd like to select the option value named 'apples' without actually knowing its index in the select box. Is this even remotely possible?

<select id="idofselectbox">
<option value="oranges">oranges</option>
<option value="pears">pears</option>
<option value="apples">apples</option>
<option value="strawberries">strawberries</option>
</select>
BobbyJones
  • 1,331
  • 1
  • 26
  • 44
  • 2
    Possible duplicate of [How do you select a particular option in a SELECT element in jQuery?](https://stackoverflow.com/questions/314636/how-do-you-select-a-particular-option-in-a-select-element-in-jquery) – devlin carnate Jan 31 '18 at 20:13

1 Answers1

4

You can set the value as if it's a regular combo box, then call refresh on selectic to refresh the UI.

$('#idofselectbox').val('apples').selectric('refresh'); 
Eliellel
  • 1,426
  • 1
  • 9
  • 14