Dinesh G
Dinesh G

Reputation: 1365

How select multiple dropdown in jquery?

Example

<select name="test" multiple="multiple">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>

Select One value from dropdown is

$("select[name=test]").val("1");

But How to select multiple options using jquery?

enter image description here

Please help to solve my problem.

Upvotes: 2

Views: 12719

Answers (2)

Krupesh Kotecha
Krupesh Kotecha

Reputation: 2412

Try this

$("select[name=test]").val([1,2,3]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="test" multiple="multiple">
  <option value="1">1 This is first</option>
  <option value="2">2 This is second</option>
  <option value="3">3 This is third</option>
  <option value="4">4 This is fourth</option>
</select>

Upvotes: 7

dieuvn3b
dieuvn3b

Reputation: 6114

You can try it:

$('select option[value=' + val + ']').attr('selected', true);

Upvotes: 3

Related Questions