Начало
Формы
Коробки предела
Ограничивает число checkboxes, что пользователь в состоянии проверить Ваш сайт.
Please choose up to 2 sections: (or check all three and see what happens!)
Section 1
Section 2
Section 3
JavaScript Forms: Коробки предела
<!-- TWO STEPS TO INSTALL LIMIT BOXES: 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 countChoices(obj) { max = 2; // max. number allowed at a time box1 = obj.form.box1.checked; // your checkboxes here box2 = obj.form.box2.checked; box3 = obj.form.box3.checked; // add more if necessary count = (box1 ? 1 : 0) + (box2 ? 1 : 0) + (box3 ? 1 : 0); // If you have more checkboxes on your form // add more (box_ ? 1 : 0) 's separated by '+' if (count > max) { alert("Oops! You can only choose up to " + max + " choices! \nUncheck an option if you want to pick another."); obj.checked = false; } } // End --> </script> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <center> <form> Please choose up to 2 sections: <p> <input type=checkbox name=box1 onClick="countChoices(this)">Section 1 <p> <input type=checkbox name=box2 onClick="countChoices(this)">Section 2 <p> <input type=checkbox name=box3 onClick="countChoices(this)">Section 3 <p> </form> </center> <!-- Script Size: 1.55 KB -->