Limitar cantidad de checkbox seleccionados de un div

<script language="javascript"> //VALIDACION CHECKBOX function validacion(formu, obj) { limite=1; //limite de checks a seleccionar num=0; if (obj.checked) { for (i=0; ele=document.getElementById(formu).children[i]; i++) if (ele.checked) num++; if (num>limite) obj.checked=false; } } </script> <div id="form1"> <input type="checkbox" name="check1" onchange="validacion('form1', this)" /> <input type="checkbox" name="check2" onchange="validacion('form1', this)" /> <input type="checkbox" name="check3" onchange="validacion('form1', this)" /> <input type="checkbox" name="check4" onchange="validacion('form1', this)" /> </div> <div id="form2"> <input type="checkbox" name="check1" onchange="validacion('form2', this)" /> <input type="checkbox" name="check2" onchange="validacion('form2', this)" /> </div>
Limit number of selected checkboxes

permite que solo sea seleccionado un limite maximo de checks ubicados dentro de un div.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.