Jump to content

Checking all checkboxes .. in a table within a form?


nimzie

Recommended Posts

I found this script:

<script language="JavaScript"> 

function Checkall(form){ 
  for (var i = 1; i < form.elements.length; i++){    
    eval("form.elements[" + i + "].checked = form.elements[0].checked");  
  } 
}
</script>

 

Trying to go through this table and check / uncheck all the checkboxes as anyone would expect a check all checkbox to do...

 

I build the table with a loop/php from a query, so there can be many records.

 

Right now, if I check 3 checkboxes in the table, then click check all, they all uncheck.

The "check all" control isn't getting checked when I click it and if I click the main one without anything checked, it appears as if nothing happens. No checkboxes in the table do anything.

 

Please advise :)

Thanks,

 

Adam

 

<form name="myForm" action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="post">
    <input type="checkbox" onClick="Checkall('myForm');" />Check all Records<br />
    <table>
         <tr>
           <td>Process Order</td>
           <td>OrderID</td>
         </tr>
         <tr>
           <td> <input type="checkbox" name="checkbox" ><br /> </td>
           <td>orderid</td>
         </tr>
    </table>
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.