This question asks how to get all the selected <options> of the <select> element and return their values to a comma-separated list. JQuery - multiple choice options
I would like to do the opposite of this question; I have a list of values for a <select> , separated by commas, and I would like to select each <option> whose value is in a comma-separated list using jQuery.
Sample data:
<script type="text/javascript"> var data = "0a,0d,0f,0g"; </script> <select id="ps-type" name="ps-type" multiple="multiple" size="5"> <option value="0a">Residential - Wall Insulation</option> <option value="0b">Residential - Attic /Crawl Space Insulation</option> <option value="0c">Residential - Foundation Insulation</option> <option value="0d">Residential - Exterior Roof System</option> <option value="0e">Commercial - Wall Insulation</option> <option value="0f">Commercial - Air Barrier System (Walltite)</option> <option value="0g">Commercial - Roof System</option> </select>
source share