Archive

Posts Tagged ‘select all’

Listbox select all using checkbox through Javascript

March 29, 2010 3 comments

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>