F
Fred
Hi,
I defined a form consisting of checkboxes like:
<form>
<input type="checkbox" name=ck id=ck onclick="check(this.form)"
<input type="checkbox" name=ck id=ck onclick="check(this.form)"
.....
<input type="checkbox" name=ck id=ck onclick="check(this.form)"
</form>
1) when this function is ran, if there is only ONE checkbox into the form, i
get in the first ALERT: "undefined" and the second gives a value of 0. When
there are 2 ore more, i get the exact length and the right number of checked
checkboxes..
My question is: why and how to solve this?
function check(form)
{
var total = 0;
var mx = form.ck.length;
alert(mx)
for (var x = 0; x < mx; x++)
{
if (eval("document.chk.ck[" + x + "].checked") == true)
{ total += 1 }
}
alert(total)
2) When one checkbox is checked, i would like to disabeld all the others,
because only one may be checked.
I tried different ways, but no succesfully (in the same function as above):
"impossible to affect to a result of function" (or something ..)
if (total==1)
{
for (var x = 0; x < mx; x++)
{
if (eval("document.chk.ck[" + x + "].checked") == false)
{eval("document.chk.ck[" + x + "].disabled") = true}
}
}
Thanks again for any hints
Fred
I defined a form consisting of checkboxes like:
<form>
<input type="checkbox" name=ck id=ck onclick="check(this.form)"
<input type="checkbox" name=ck id=ck onclick="check(this.form)"
.....
<input type="checkbox" name=ck id=ck onclick="check(this.form)"
</form>
1) when this function is ran, if there is only ONE checkbox into the form, i
get in the first ALERT: "undefined" and the second gives a value of 0. When
there are 2 ore more, i get the exact length and the right number of checked
checkboxes..
My question is: why and how to solve this?
function check(form)
{
var total = 0;
var mx = form.ck.length;
alert(mx)
for (var x = 0; x < mx; x++)
{
if (eval("document.chk.ck[" + x + "].checked") == true)
{ total += 1 }
}
alert(total)
2) When one checkbox is checked, i would like to disabeld all the others,
because only one may be checked.
I tried different ways, but no succesfully (in the same function as above):
"impossible to affect to a result of function" (or something ..)
if (total==1)
{
for (var x = 0; x < mx; x++)
{
if (eval("document.chk.ck[" + x + "].checked") == false)
{eval("document.chk.ck[" + x + "].disabled") = true}
}
}
Thanks again for any hints
Fred