Hi,
I have a form with 8 check-boxes. I need to limit the users to only choose 2 checkbox before submitting the form. Is there there anyway to accomplish this with javascript?
Thanks, Mary
Hi,
I have a form with 8 check-boxes. I need to limit the users to only choose 2 checkbox before submitting the form. Is there there anyway to accomplish this with javascript?
Thanks, Mary
Hi Mary,
Try adding this to the Javascript on your Form:
function readInput(input) { var i = 0; $(".checkboxes input").each(function(){ if ($(this).prop("checked")) { i++; } }); if (i > 2) { alert("You may only pick 2 options"); $("#"+input.data.id).prop("checked", false); } } $(document).ready(function(){ $(".checkboxes input").each(function(){ $(this).on("click", {id:$(this).attr("id")}, readInput); }); });
Also for this to work you'll need to add a class called "checkboxes" to the checkboxes you need to validate on your form.
I hope this helps!
Cheers, Dan