Suchy Posted April 7, 2008 Share Posted April 7, 2008 I am having trouble with counting checkboxes // Form <form action="<?=$_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return checkform(this);" > <label><input type="checkbox" name="win_ver[]" value="00">Windows 95</label><br /> <label><input type="checkbox" name="win_ver[]" value="01">Windows 98</label><br /> <label><input type="checkbox" name="win_ver[]" value="02">Windows ME</label><br /> <label><input type="checkbox" name="win_ver[]" value="03">Windows XP</label><br <label><input name="OK" type="submit" value="OK" /><label> </form> function checkform(form1) { var total = 0; for (i = 0; i <12; i++) { if ((form1.win_ver[i].checked)) { total += 1; } } alert("You selected " + total + " boxes."); return false; } What is wrong with this ? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 7, 2008 Share Posted April 7, 2008 This should work for you: function checkform(form1) { var total = 0; for(i=0;i < form1['win_ver[]'].length;i++) { if ((form1['win_ver[]'][i].checked)) { total += 1; } } alert("You selected " + total + " boxes."); return false; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.