charbort
01-29-2003, 03:31 PM
I have the following code and am having trouble revising it to make it work with changed checkbox input names. I want to change the names from all being "checkbox" to "subject1", "subject2",..... etc.
Any suggestions?
Thanks,
charbort
<script Language="JavaScript">
<!--
function checkbox_checker()
{
// set var checkbox_choices to zero
var checkbox_choices = 0;
// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < checkbox_form.checkbox.length; counter++)
{
// If a checkbox has been selected it will return true
// (If not it will return false)
if (checkbox_form.checkbox[counter].checked)
{ checkbox_choices = checkbox_choices + 1; }
}
if (checkbox_choices < 1 )
{
// If there were no selections made display an alert box
msg="Please make a selection.\n"
msg=msg + "You have made " + checkbox_choices + " selections.\n"
msg=msg + "Please make at least one selection."
alert(msg)
return (false);
}
// If three were selected then display an alert box stating input was OK
alert(" *** Valid input was entered. ***");
return (true);
}
-->
</script>
<form method="get" action="#"
onsubmit="return checkbox_checker()" name="checkbox_form">
<input type="checkbox" value="Submit1" name="checkbox">Subscriber 1<br>
<input type="checkbox" value="Submit2" name="checkbox">Subscriber 2<br>
<input type="checkbox" value="Submit3" name="checkbox">Subscriber 3<br>
<input type="checkbox" value="Submit4" name="checkbox">Subscriber 4<br>
<input type="checkbox" value="Submit5" name="checkbox">Subscriber 5<br>
<input type="submit" value="Submit">
</form>
Any suggestions?
Thanks,
charbort
<script Language="JavaScript">
<!--
function checkbox_checker()
{
// set var checkbox_choices to zero
var checkbox_choices = 0;
// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < checkbox_form.checkbox.length; counter++)
{
// If a checkbox has been selected it will return true
// (If not it will return false)
if (checkbox_form.checkbox[counter].checked)
{ checkbox_choices = checkbox_choices + 1; }
}
if (checkbox_choices < 1 )
{
// If there were no selections made display an alert box
msg="Please make a selection.\n"
msg=msg + "You have made " + checkbox_choices + " selections.\n"
msg=msg + "Please make at least one selection."
alert(msg)
return (false);
}
// If three were selected then display an alert box stating input was OK
alert(" *** Valid input was entered. ***");
return (true);
}
-->
</script>
<form method="get" action="#"
onsubmit="return checkbox_checker()" name="checkbox_form">
<input type="checkbox" value="Submit1" name="checkbox">Subscriber 1<br>
<input type="checkbox" value="Submit2" name="checkbox">Subscriber 2<br>
<input type="checkbox" value="Submit3" name="checkbox">Subscriber 3<br>
<input type="checkbox" value="Submit4" name="checkbox">Subscriber 4<br>
<input type="checkbox" value="Submit5" name="checkbox">Subscriber 5<br>
<input type="submit" value="Submit">
</form>