Click to See Complete Forum and Search --> : Counting Cjeckbox Selections
lauranr
01-11-2003, 09:40 AM
I am relatively new to JS and forms. I am starting to develop an application in which the user can select any number of items (from 1 to 20) on a checkbox list. Redirection depends upon how many selections were made -- one selection sends the user to Page A, two selections sends him to Page B, and so on. Is there a way to count the number of checkbox selections that were made? Any help appreciated!!
Try it with location.href for some checked boxes:
<script language="JavaScript">
<!--
function locate(form){
var elm = new Array("test2","test3");
var loc = new Array("onechecked.html","twochecked.html")
var len = form.elements.length;
a = -1;
for (i=0; i<len; i++ ) {
if(form.elements[i].name.indexOf(elm[i]) >-1)
{
if(form.elements[i].checked == true)
{
a++;
}
}
}
window.location.href=loc[a];
}
//-->
</script>
<body>
<form name=creator onSubmit="locate(this);return false;">
<input type="Checkbox" name="test2" value="v">
<input type="Checkbox" name="test3" value="v">
<input type="Submit" name="test4" value="locate">
</form>
</body>