Forums

PHP

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>&lt;input name="checkAll" type="checkbox" onclick="checkAll(document.myFormName.chkUpdateStatus)" value="checkAll" title="Check all Jobs" /&gt;
&lt;input name="uncheckAll" type="checkbox" onclick="uncheckAll(document.myFormName.chkUpdateStatus)" value="uncheckAll" title="Uncheck all Jobs" /&gt;</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>&lt;input type="checkbox" name="chkUpdateStatus[]" value="&lt;?=$row_rsCurrentJobOrders['jobID']?&gt;" /&gt;</font id=code></pre id=code>


Here's the JS function code:
<pre id=code><font face=courier size=2 id=code>&lt;!--
// 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:

// &lt;input type="button" name="CheckAll" value="Check All"
//onClick="checkAll(document.myform.list)"&gt;

// &lt;input type=button name="UnCheckAll" value="Uncheck All"
//onClick="uncheckAll(document.myform.list)"&gt;
// --&gt;

&lt;!-- Begin
function checkAll(field)
{
for (i = 0; i &lt; field.length; i++)
field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i &lt; field.length; i++)
field[i].checked = false ;
}
// End --&gt;</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>&lt;input type="checkbox" name="ItemID[&lt;?php echo $row_ItemsRS['ItemID']; ?&gt;]" value="&lt;?php echo $row_ItemsRS['ItemID']; ?&gt;"&gt;</font id=code></pre id=code>

___________________________________
* Sorry... how do you do that again?... *

Reply to this topic