I have the following select box on a form with an unknown number of options:
<select>
<option value="v1">v1</option>
<option value="v2">va2</option>
<option value="v3">va3</option>
<option value="v11">v11</option>
<option value="v12">va12</option>
<option value="v13">va13</option>
</select>
I have the following array defined in javascript:
var checkValArray = ['v1', 'v2', 'v13'];
What I would like to do is go through every option of the select box and see whether an element of my array is equal to it.
What would be the best way to put this into practice?
Your help is highly appreciated.
There’s a very useful jQuery API method: $.inArray. So it should be something like this:
For multiselects it may be used with something like…