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 ? Link to comment https://forums.phpfreaks.com/topic/100004-counting-selections/ 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; } Link to comment https://forums.phpfreaks.com/topic/100004-counting-selections/#findComment-511386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.