I have 56 checkboxes with the name “AG”.
I’m trying to check how many “AG” checkboxes were checked.
The function i have right now is this.
[php]function ag () {
$AG = $_POST[‘AG’];
$num = count($AG);
return $num;
}[/php]
But this returns 1 if at least one of the “AG” checkboxes were checked and 0 if none were checked.
How do i get it to check how MANY “AG” checkboxes were checked?.. I’m stumped…
[php]
<?php Function ag() { $HowMany= 0; for($i=0;$i<$_REQUEST['AG'];$i++) { $HowMany = $HowMany + 1; } return $HowMany; } ?>[/php]
let me know if that worked for you
nope…
its returning a 0 now no matter how many boxes i check…
wow that is very weird. can you show me the html form so i can test it.
only the form.
[code]Please check the box if you took a course in the respective subject in that semester.
8th Sem 1 | 8th Sem 2 | 9th Sem 1 | 9th Sem 2 | 10th Sem 1 | 10th Sem 2 | 11th Sem 1 | 11th Sem 2 | 12th Sem 1 | 12th Sem 2 | Select All Semesters | |
---|---|---|---|---|---|---|---|---|---|---|---|
History | |||||||||||
English | |||||||||||
Mathematics | * | * | |||||||||
Science | |||||||||||
Foreign Language | |||||||||||
Visual and Performing Arts | |||||||||||
Electives |
that’s the code for the checkbox table
I did not manage to make it work. but other PHP buddies will take a look
what is wrong with this function?
[php]
[/php]
it should counts all the selected checkboxes bur when i call the functions always return 0. what is wrong?
I ‘solved’ the problem by changing the name of the checkboxes to ‘AG[]’ apparently when you pass things to php you have to pass it in array form for it to understand… It caused some new problems in javascript but i was able to fix it.
im glad that you fixed, so my function did not have any errors in it right?