kupendra
kupendra

Reputation: 1003

jquery for select all item in multiple select list box

Jquery for select all item in multiply select list box.

$("#pl_new").find("option").each(function() {
     $(this).attr('selected', true);
});

This is not work to select all item in list box when form submitted.

Upvotes: 1

Views: 3737

Answers (1)

Afzaal Ahmad Zeeshan
Afzaal Ahmad Zeeshan

Reputation: 15860

jQuery code:

You need to be using

$(this).prop('selected', true);

But if you still wanna use attr() then use this:

$(this).attr('selected', 'selected'); // your method is also OK!

Select multiple attribute:

P.S, please check that whether the select tag has the multiple attribute in it or not ;) since that might be the cause of the problem.

Since in this fiddle: http://jsfiddle.net/afzaal_ahmad_zeeshan/tusUA/1/ by Kevin, you can see the multiple attribute applied to the select and the code is working.

Upvotes: 2

Related Questions