»
AnglaisFrançaisVietnamien

Imprimer - Limite Boxes script - JavaScriptBank.com

Version complète: jsB@nk » Form » Checkbox » Limite Boxes script
URL: https://www.javascriptbank.com/limit-boxes-script.html

Limite Boxes script © JavaScriptBank.comLimite le nombre de cases que l'utilisateur est en mesure de vérifier sur votre site. Idéal pour les situations où plus d'une sélection est autorisée jusqu'à un certain nombre global. Si ils choisissent de trop nombreux, ils sont informés de la durée maximale autorisée et de leur dernière entrée devient incontrôlée.

Version complète: jsB@nk » Form » Checkbox » Limite Boxes script
URL: https://www.javascriptbank.com/limit-boxes-script.html



JavaScript
<SCRIPT LANGUAGE="JavaScript">// Glenn Wang (brief@ix.netcom.com) | http://capsule.bayside.net/<!-- Beginfunction countChoices(obj) {max = 2; // max. number allowed at a timebox1 = obj.form.box1.checked;  // your checkboxes herebox2 = obj.form.box2.checked;box3 = obj.form.box3.checked;  // add more if necessarycount = (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><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<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><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->