Home > Javascript > Listbox select all using checkbox through Javascript

Listbox select all using checkbox through Javascript


In this article, we gonna implement selection of all items in listbox using checkbox through javascript.

<script language=”javascript” type=”text/javascript”>

function SelectAllCountry(chkObj) {
var multi = document.getElementById(‘lstcountry’);
if (chkObj.checked)
for (i = 0; i < multi.options.length; i++)
multi.options[i].selected = true;
else
for (i = 0; i < multi.options.length; i++)
multi.options[i].selected = false;
}

</script>

<asp:CheckBox ID=”chkcountry” OnClick=”SelectAllCountry(this);”
runat=”server” Text=”Select All” />

<asp:ListBox ID=”lstcountry” runat=”server” Rows=”10″ SelectionMode=”Multiple”>

<asp:ListItem Text=”Australia” Value=”Australia”></asp:ListItem>

<asp:ListItem Text=”Germany” Value=”Germany”></asp:ListItem>

<asp:ListItem Text=”Holland” Value=”Holland”></asp:ListItem>

<asp:ListItem Text=”India” Value=”India”></asp:ListItem>

<asp:ListItem Text=”Japan” Value=”Japan”></asp:ListItem>

</asp:ListBox>

Advertisements
  1. April 20, 2010 at 9:32 pm

    Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.

  2. joyce
    April 20, 2012 at 8:38 pm

    It’s very nice! I just finish one of my task based on your post! Thank you!

  3. praveenkumar
    October 30, 2013 at 11:41 am

    Thak U

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: