P
payne747
Hi everyone,
Can anyone help me with the following code, for some reason I can't
understand if I'm being thick of if javascript is so backwards!
HTML defines some checkboxes such as:
<form name="players_form">
<input type="checkbox" name="check1" value="blabla"
onclick="UpdatePlayers()" />
<input type="checkbox" name="check2" value="blabla"
onclick="UpdatePlayers()" />
.... (10 checkboxes in total)
</form>
The UpdatePlayers() function looks like this:
function UpdatePlayers()
{
for(i=0; i<10; i++) // always will be 10 checkboxes so run 10
times.
{
if (document.players_form.check.checked == true)
{
players++;
}
else {
players--;
}
}
document.all.output.innerHTML = players;
}
This bit of code is supposed to return the amount of boxes checked via
the 'players' variable. However the error thrown back is:
document.players_form.check - null or unknown object
For some reason, the variable 'i' is not being appended to the check
name. Does anyone know of a better way to do this? Basically the aim is
to just dynamicaly count the amount of checked boxes on a screen.
Thanks!
Payne747
Can anyone help me with the following code, for some reason I can't
understand if I'm being thick of if javascript is so backwards!
HTML defines some checkboxes such as:
<form name="players_form">
<input type="checkbox" name="check1" value="blabla"
onclick="UpdatePlayers()" />
<input type="checkbox" name="check2" value="blabla"
onclick="UpdatePlayers()" />
.... (10 checkboxes in total)
</form>
The UpdatePlayers() function looks like this:
function UpdatePlayers()
{
for(i=0; i<10; i++) // always will be 10 checkboxes so run 10
times.
{
if (document.players_form.check.checked == true)
{
players++;
}
else {
players--;
}
}
document.all.output.innerHTML = players;
}
This bit of code is supposed to return the amount of boxes checked via
the 'players' variable. However the error thrown back is:
document.players_form.check - null or unknown object
For some reason, the variable 'i' is not being appended to the check
name. Does anyone know of a better way to do this? Basically the aim is
to just dynamicaly count the amount of checked boxes on a screen.
Thanks!
Payne747