4

I am new to jquery, I am trying to validate a group of checkboxes[] using the validation plugin. After searching the internet I came across this AddMethod( ) which seems to resolve the issue of checkboxes, but I can not find any piece of code that explains how to apply the new method name to the validate().

Here is my code of what I am trying to achieve

<script type="text/javascript">

jQuery.validator.addMethod('minchecked',function(value, element) {
          return $(element).filter(':checked').length >= 1;
}, 'please make a selection');

$(document).ready(function(){
   $("#onlinesurvey").validate({
      rules: {
         <!== do not know how apply the new method if it does go here ==>
      }
    });
});
</script>

<html>
<body>
<form id="onlinesurvey">
<fieldset id="stageone">
<label for="q1a"><input type="checkbox" name="q1[]" id="q1a" value="Blue Square Casino" />Blue Square Casino</label>
<label for="q1b"><input type="checkbox" name="q1[]" id="q1b" value="Paddy Power" />Paddy Power</label>
<label for="q1c"><input type="checkbox" name="q1[]" id="q1c" value="Sky Vegas" />Sky Vegas</label>
<label for="q1d"><input type="checkbox" name="q1[]" id="q1d" value="Virgin Casino" />Virgin Casino</label>
<label for="q1e"><input type="checkbox" name="q1[]" id="q1e" value="Other(s)" />Other(s)</label>
<label for="q1[]" class="error">Please make a selection</label>
</div>  
<input type="button" value="next" class="next" />
</fieldset>
</form>
</body>
</html>
1
  • 1
    You should enter an answer with your solution and accept it. Commented Feb 23, 2010 at 21:39

1 Answer 1

2
$("#onlinesurvey").validate({
  rules: {
     minchecked: true
  }
});
Sign up to request clarification or add additional context in comments.

1 Comment

I applied that piece of code but it still didn't work - my confusion is the addMethod "minchecked" applied to every checkbox inn that form

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.