lets start by giving your form an id. lets call it chekform <form id="checkform"> ... <!-- say we have our checkboxes in here along with our submit lets give all of our checkboxes a class called "check" --> </form>
THE JQUERY $(function() { var obj = $("#checkform"); // create a reference to the object var checkboxes = $("input.check", obj); // a reference to each check box with the class check var value; // variable that's is going to count how many boxes are checked //click function checkboxes.click(function() { var current = index($(this)); //gets the eq of the element clicked // if checkbox is checked. uncheck. else check if(checkboxes.eq(current).atrrib("checked") == "checked") { checkboxes.eq(current).atrrib("checked") == "" value--; //decrement value } else { checkboxes.eq(current).atrrib("checked") = "checked"; value++ //increment value } }); /* from here on you can say submit if value > 7 */ }); On Sun, May 3, 2009 at 1:46 AM, ameri...@gmail.com <ameri...@gmail.com>wrote: > > Hello, > > Trying to use jquery to validate that a minimum of 7 check boxes are > selected. the code is as follows: > > $(document).ready(function() > { > $("form").submit(function() > { > if (!isCheckedById("AreasOfInterest[]")) > { > alert ("Please select at least 7 items"); > return false; > } > else > { > return true; //submit the form > } > }); > > function isCheckedById(id) > { > var checked = $("inp...@id="+id+"]:checked").length; > if (checked < 7) > { > return false; > } > else > { > return true; > } > } > }); > > It works if i set the (checked == 0) and then at least 1 is > selected... but when i run it as is... it won't submit even if more > than 7 are selected... Is my code wrong?? is the variable checked not > an integer?? help!! >