Check All Checkboxes

S

shankwheat

I need to create to create a function that checks all checkboxes within
pnlSearchValues. This isn't working - no errors. Can someone help me
out? Thanks.

<script type="text/javascript">
function SelectAll(CheckBoxControl)
{
if (CheckBoxControl.checked == true)
{
var i;
for (i=0; i < document.forms[0].elements.length; i++)
{
if ((document.form[0].elements.type == 'checkbox') &&
(document.form[0].elements.name.indexOf('pnlSearchValues') >
-1))
{
document.form[0].elements.checked = true;
}
}
}
else
{
var i;
for (i=0; i < document.forms[0].elements.length; i++)
{
if ((document.form[0].elements.type == 'checkbox') &&
(document.form[0].elements.name.indexOf('pnlSearchValues') >
-1))
{
document.form[0].elements.checked = false;
}
}
}
}
</script>

<form id="form1" runat="server">
<asp:panel ID="pnlSearchValues" runat="server" Width="98%">

<input type="checkbox" name="SelectAllCheckBox"
onclick="SelectAll(this)">

<asp:CheckBox ID="chkTicker" runat="server" Text="Ticker"
CssClass="CheckBoxText" />
<asp:CheckBox ID="chkCompanyName" runat="server" Text="Company Name"
CssClass="CheckBoxText" />
<asp:CheckBox ID="chkIndustry" runat="server" Text="Industry"
CssClass="CheckBoxText" />

etc...

</form>
 
L

Lee

shankwheat said:
I need to create to create a function that checks all checkboxes within
pnlSearchValues. This isn't working - no errors. Can someone help me
out? Thanks.

You need to rethink how you work with boolean values.
Never compare a boolean value to true. True is true.
You could cut the size of your function in half:

document.form[0].elements.checked = CheckBoxControl.checked;


You've posted ASP code. Don't do that.
Show us the client-side code that the Javascript acts on.
I don't see any form elements that contain "pnlSearchValues"
in their NAME attributes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top