I am trying to select items in the following select multiple by there value. The code is below:
<select id="genre" name="genre" multiple="multiple" size="9">
<option value="1">Action</option>
<option value="2">Adult</option>
<option value="3">Adventure</option>
<option value="4">Comedy</option>
<option value="5">Drama</option>
</select>
I can select one or two options but the thing is that the number of selected options comes from user which i’m change it to something like this: 1,2,4 (by value).
You can select multiple options by passing an array of values to the
.val()function:If instead of an array, you have a comma delimited string, just transform it to an array using
split(), before passing it to.val():From the docs: