Reputation: 11662
I have asp.net listbox. first item of the listbox is "--All--". If user selected 1st item of the list then automatically select all items. If user unselect 1st item of list then automatically unselect all items. How can I do that using jquery?
<asp:ListBox ID="lstDatabases" runat="server" Height="134px" Width="396px" SelectionMode="Multiple" >
</asp:ListBox>
Upvotes: 2
Views: 10186
Reputation: 24488
jQuery: Select all options in a Multiple Select Listbox
$("#multipleselect option").prop("selected",true);
A multiple select listbox with everything already selected for you!
From : http://www.craiglotter.co.za/2010/02/26/jquery-select-all-options-in-a-multiple-select-listbox/
Upvotes: 3
Reputation: 189
You can try something like this:
$("#selectId").on('change', function() {
if ($(this).val() == "all") {
$("select > option").prop("selected", true);
}
});
Upvotes: 4