Link to home
Start Free TrialLog in
Avatar of ZekeLA
ZekeLAFlag for United States of America

asked on

jquery selector doesn't check/uncheck all checkboxes from ASP.NET checkboxlist

I have a .NET form with two links (select all / none) that should check / uncheck all the checkboxes from a checkboxlist. Unfortunately, there's a bug in my selector and the checkboxes remain unchanged. My source is below.

Can someone tell me where my error is?

Thanks in advance.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Page</title>
<script src='/MyLocalDomain/Scripts/jquery-1.4.4.min.js' language='javascript' type='text/javascript'></script>
<script src='/MyLocalDomain/Scripts/jquery-ui-1.8.7.custom.min.js' language='javascript' type='text/javascript'></script>
<script type="text/javascript">
function checkAll(pid, check) {
   $('#' + pID + ' input[type=checkbox]').attr('checked', check);
   return false;
}
</script>
</head>

<body id="ctl00_MainBody" bgcolor="#ffffff" leftmargin="0" topmargin="0">
<form name="aspnetForm" method="post" action="MyPage.aspx" id="aspnetForm">

<table>
   <tr>
      <td class="txt-bodyimportant" vAlign="top" align="right" >
      Tests:
      <br /><a id="lnkSelectAll" href="" onclick="return checkAll('tdTest', true);">Select All</a>
      <br /><a id="lnkSelectNone" href="" onclick="return checkAll('tdTest', false);">Select None</a>
      </td>
      <td id="tdTest">
         <table id="ctl00_MainContent_chklstTests" >
            <tr>
               <td>
                  <input id="ctl00_MainContent_chklstTests_0" type="checkbox" name="ctl00$MainContent$chklstTests$0" />
                  <label for="ctl00_MainContent_chklstTests_0">Test Zero</label>
               </td>
               <td>
                  <input id="ctl00_MainContent_chklstTests_7" type="checkbox" name="ctl00$MainContent$chklstTests$7" />
                  <label for="ctl00_MainContent_chklstTests_7">Test One</label>
               </td>
               <td>
                  <input id="ctl00_MainContent_chklstTests_13" type="checkbox" name="ctl00$MainContent$chklstTests$13" />
                  <label for="ctl00_MainContent_chklstTests_13">Test Two</label>
               </td>
            </tr>
         </table>
      </td>
   </tr>
</table>

</form>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZekeLA

ASKER

Aargh! I should have spotted that. Thank you.