Click all "Checkboxes" at once

Results 1 to 3 of 3

Thread: Click all "Checkboxes" at once

  1. #1
    Dat Guest

    Default Click all "Checkboxes" at once

    Hi,<BR><BR>I have a grid that is populated with checkboxes.<BR>These checkboxes were all created at runtime and<BR>have the same "id".<BR>I have a button and if clicked on, I would like it<BR>to check all of the created "checkboxes". How would<BR>I go about doing this?<BR><BR>Thanks,

  2. #2
    Ian Stallings Guest

    Default RE: Click all

    This is not ASP. but:<BR><BR>&#060;script language="JavaScript"&#062;<BR>function CheckAll(){<BR><BR>for(i=0;i&#060;=(checkBoxName.l ength-1);i++){<BR>checkBoxName[i].checked = true;<BR> }<BR><BR>}<BR>&#060;/script&#062;<BR><BR><BR>You would call this from the checkbox like so:<BR>&#060;input type="checkbox" name="checkBoxName" onClick="CheckAll();"&#062;<BR><BR><BR><BR>Please forgive me of this code doesn&#039t work but I didn&#039t test it.<BR>It should give you the idea of how to accomplish this. Basically<BR>If there is more than one checkbox on the page with the same<BR>name then they are placed in an array and you can access those<BR>values using the index. IE. - checkBoxName[0].value<BR><BR><BR>remember that Javascript is case sensitive and here is a good<BR>site to get info on Javascript:<BR>

  3. #3
    Ben Jiang Guest

    Default RE: Click all

    You can create a javascript like this:<BR>function CheckAllBoxes()<BR>{<BR> var checkboxcount = document.frmName.chkname.length;<BR> for(var i=0;i&#060;checkboxcount;i++)<BR> document.frmName.chkname[i].checked = true;<BR>}<BR>Suppose you create the check boxes and the button like this:<BR>&#060;form name="frmName" method="post"&#062;<BR>&#060;input type="checkbox" name="chkname"&#062;<BR>&#060;input type="checkbox" name="chkname"&#062;<BR>....<BR>&#060;input type="button" value="Check All" onclick="javascript:CheckAllBoxes()"&#062;<BR>&#06 0;/form&#062;<BR><BR><BR>Hope this will help. <BR>Ben Jiang

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts