Forums
This topic is locked
PHP & JS - CheckAll & UncheckAll buttons
Posted 12 Apr 2005 00:29:44
1
has voted
12 Apr 2005 00:29:44 Chris Charlton posted:
<i>DMX2004, PHP, MySQL, JS, XHTML</i><b>Background:</b> I am using a checkbox array for a dynamic table that posts to a page that will do a multiple UPDATE in the database. Hence the [] brackets in the checkbox names.
<b>Problem:</b> I don't think the JS function is likes the brackets [], so I've tried with and without with no results.
<b>Code</b>: I call two JS functions, <i>checkAll</i> & <i>uncheckAll</i>.
<pre id=code><font face=courier size=2 id=code><input name="checkAll" type="checkbox" onclick="checkAll(document.myFormName.chkUpdateStatus)" value="checkAll" title="Check all Jobs" />
<input name="uncheckAll" type="checkbox" onclick="uncheckAll(document.myFormName.chkUpdateStatus)" value="uncheckAll" title="Uncheck all Jobs" /></font id=code></pre id=code>
And here's the XHTML for the checkbox that's a repeated row in a dynamic table (PHP).
<pre id=code><font face=courier size=2 id=code><input type="checkbox" name="chkUpdateStatus[]" value="<?=$row_rsCurrentJobOrders['jobID']?>" /></font id=code></pre id=code>
Here's the JS function code:
<pre id=code><font face=courier size=2 id=code><!--
// by Nannette Thacker - www.shiningstar.net
// This script checks and unchecks boxes on a form. Checks and unchecks unlimited number in the group...
// Pass the Checkbox group name... call buttons as so:
// <input type="button" name="CheckAll" value="Check All"
//onClick="checkAll(document.myform.list)">
// <input type=button name="UnCheckAll" value="Uncheck All"
//onClick="uncheckAll(document.myform.list)">
// -->
<!-- Begin
function checkAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}
function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}
// End --></font id=code></pre id=code>
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
Replies
Replied 15 Apr 2005 21:50:07
15 Apr 2005 21:50:07 Matt Bailey replied:
In the XHTML bit, what about actually giving the 'name' array actual values. By way of example here's a bit of code I've used before that sets up an array for multiple inserts:
<pre id=code><font face=courier size=2 id=code><input type="checkbox" name="ItemID[<?php echo $row_ItemsRS['ItemID']; ?>]" value="<?php echo $row_ItemsRS['ItemID']; ?>"></font id=code></pre id=code>
___________________________________
* Sorry... how do you do that again?... *
<pre id=code><font face=courier size=2 id=code><input type="checkbox" name="ItemID[<?php echo $row_ItemsRS['ItemID']; ?>]" value="<?php echo $row_ItemsRS['ItemID']; ?>"></font id=code></pre id=code>
___________________________________
* Sorry... how do you do that again?... *