Reputation: 1003
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
Reputation: 15860
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!
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