Начало
Формы
Прилавок Checkbox
Легко посчитайте число checkboxes, которые были отобраны.
1
2
3
4
5
6
7
8
9
JavaScript Forms: Прилавок Checkbox
<!-- TWO STEPS TO INSTALL CHECKBOX COUNTER: 1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document --> <!-- STEP ONE: Paste this code into the HEAD of your HTML document --> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <! > <! > <!-- Begin function anyCheck(form) { var total = 0; var max = form.ckbox.length; for (var idx = 0; idx < max; idx++) { if (eval("document.playlist.ckbox[" + idx + "].checked") == true) { total += 1; } } alert("You selected " + total + " boxes."); } // End --> </script> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <form method="post" name=playlist> 1<input type=checkbox name=ckbox> <br>2<input type=checkbox name=ckbox> <br>3<input type=checkbox name=ckbox> <br>4<input type=checkbox name=ckbox> <br>5<input type=checkbox name=ckbox> <br>6<input type=checkbox name=ckbox> <br>7<input type=checkbox name=ckbox> <br>8<input type=checkbox name=ckbox> <br>9<input type=checkbox name=ckbox> <p><input type=button value="Count Checkboxes" onClick="anyCheck(this.form)"> </form> <!-- Script Size: 1.60 KB -->