I have list select:
<select id="sel">
<option id="a1" value="volvo">Volvo</option>
<option id="a2" value="saab">Saab</option>
<option id="a3" value="mercedes">Mercedes</option>
<option id="a4" value="audi">Audi</option>
<option id="a5" value="volvo2">Volvo2</option>
<option id="a6" value="saab2">Saab2</option>
<option id="a7" value="mercedes2">Mercedes2</option>
<option id="a8" value="audi2">Audi2</option>
</select>
and in PHP i have array:
$array = array('a1', 'a4', 'a5', 'a8');
How to with jQuery show in select #sel only values where id option is isset in $array of PHP?
For this example should be:
<select id="sel">
<option id="a1" value="volvo">Volvo</option>
<option id="a4" value="audi">Audi</option>
<option id="a5" value="volvo2">Volvo2</option>
<option id="a8" value="audi2">Audi2</option>
</select>
I dont want use PHP for this. I would like use jQuery. Thanks!
Using the php array you can generate the selector like this and remove or hide unwanted options.
You can render the array or selector(
'#a1, #a4, #a5, #a8') itself from server side and use it on the client side.If its an array you can try this.
Working demo – http://jsfiddle.net/TZCcA/1/