...

check all checkboxes

leena
06-18-2002, 11:04 PM
I am trying to get a link that when clicked it will check all the checkboxes in my form.

My problem is that my values are stored in an array:
<INPUT TYPE=\"checkbox\" name=\"emailArray[]\" value=\"$email\">


print"<br><a href=\"#\" onClick=\"checkAll()\">check all</a><br>";

Here is my javascript function :
function checkAll(){
alert('hi');
var df = document.selectEmailForm.elements;

for (var i = 0; i < df.length; i++) {
if (df[i].name == "emailArray[]" ) {
document.selectEmailForm.emailArray[i].checked=true;
}
}
}

Any ideas? Any help is greatly appreciated.
Thanks for your time!

Zvona
06-19-2002, 07:47 AM
Hmz..I'm wondering why are you using emailArray[] as a name? Wouldn't only emailArray or aEmail be better, because brackets has no function in this case?

Also:
<script type="text/javascript">
function zCheckAll(oForm)
{
var oElems = oForm.elements;

for (var iI=0;oElems.length>i;i++)
{
if (oElems[iI].type == "checkbox")
oElems[iI].checked = true;
}
}
</script>

function is launched eg :
<a href="#" onclick="zCheckAll(yourFormName);" title="Check all boxes">Check 'em</a>

Note : yourFormName is inserted in code without parenthesis, like myForm, not "myForm".

JohnKrutsch
06-19-2002, 03:44 PM
In PHP when you submit a form set up in this manner you will automatically have an array properly set up named $emailArray when it gets to the server-side. It is very handy! :)

Rah123
05-18-2006, 03:56 PM
well i needed the same thing because of php, so i was searching it and i saw your thread. so i used your script to make it work for both of us. here it is:

<script language=javascript>
<!--
function checkall()
{
var df=document.form1.elements;
for(var i=0;i<df.length;i++)
{
//alert(df[i].name);
df[i].checked=true;
}
}

function uncheckall()
{
var df=document.form1.elements;
for(var i=0;i<df.length;i++)
{
//alert(df[i].name);
df[i].checked=false;
}
}
-->
</script>
/* where form1 is of course the name of your form */

BonJoviFan
02-08-2012, 11:29 PM
I have been searching for a code like this for about a year now!!! Thank you guys so much! I greatly appreciate it!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum