SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: Checking all checkboxes
-
Aug 11, 2001, 12:35 #1
- Join Date
- Jul 2001
- Location
- So. Tenn.
- Posts
- 363
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Checking all checkboxes
Hi,
I have some check boxes dynamically generated from php, and I'd like to be able to have a link to "select them all".
This is what I have so far:
within my body tag:
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}
// End -->
</script>
the form name is "categories" and the checkboxes look like this:
<input type=\"checkbox\" name=\"cat[]\" value=\"$row[catid]\" class=\"form\">
and my link to select them all look like this:
<a href=\"#\" onClick=\"checkAll('document.categories.cat[]')\">Select All</a>
right now, whenever I click the link, I get the error 'undefined' is null or not an object.
Any clues what's wrong?
TYIA
-
Aug 11, 2001, 12:59 #2
- Join Date
- Oct 2000
- Location
- Austin, TX
- Posts
- 1,438
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
As a matter of fact I have a script to do just this: http://anarchos.xs.mw/formtricks.phtml
ck :: bringing chris to the masses.
-
Aug 11, 2001, 13:05 #3
- Join Date
- Jul 2001
- Location
- So. Tenn.
- Posts
- 363
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Cool..thanks, just tried it.
Any clue why I'd be getting an error: "'form.elements' is null or not an object" ?
TYIA
-
Aug 11, 2001, 13:07 #4
- Join Date
- Oct 2000
- Location
- Austin, TX
- Posts
- 1,438
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's probably because [] signifies an array in javascript.
ck :: bringing chris to the masses.
-
Aug 11, 2001, 13:11 #5
- Join Date
- Jul 2001
- Location
- So. Tenn.
- Posts
- 363
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
know of any way around it from within javascript?
-
Aug 11, 2001, 14:42 #6
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi rabbitdog,
The following error:
.elements' is null or not an object"
Re the code you posted previously, why are including braces after 'cat'?
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Aug 11, 2001, 15:11 #7
- Join Date
- Oct 2000
- Location
- Austin, TX
- Posts
- 1,438
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
He did post the code at the top; cat[] is used to input it as an array in php. I don't know if there's a way around it other than the method my script uses: looping through all elements and checking if the name contains a certain string.
ck :: bringing chris to the masses.
-
Aug 11, 2001, 19:21 #8
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi Anachros,
I agree with the looping through the form (I do that in both of the checkbox script/tutorials at my site, one of which also does selectInverse), but I still don't really understand the need for the braces in the html. Why aren't the fields being called cat1...catn, and if they must physically be in an array for php, then call a function with the onClick that assigns them so? sort of:
var chkArray = new Array();
var ndx=0;
for (i=0;i < formObj.length; i++)
{
if (formObj.elements[i].type == 'checkbox') //&&form...[i].name.substr(x,y)=='something'
{
chkArray[ndx] = formObj.elements[i].value;
ndx++;
}
}
VinnyWhere the World Once Stood
the blades of grass
cut me still
Bookmarks