jQuery validate - User must select YES radio (not no) in order to conitnue -


i set jquery validate rule require yes (not no) checked in order form validate/submit. user must accept terms. if user selects no error msg , form not validate. correct way accomplish using jquery validate plugin?

<form id="myform"> <input type="radio" name="terms" id="terms1" value="yes!" class="required" title="must accept terms continue" /> yes <input type="radio" name="terms" id="terms2" value="no" class="required" title="must accept terms continue" /> no </form>  $("#myform").validate({   /* insert awesome jquery validation code here. free beer whoever answers question! */  });  

here working example: http://jsfiddle.net/thcs8/1/

kudos can provide solution or better example! vote if looking same solution gets attention. all!

please vote favorite solution!

i had problem, , tried various things including solutions mentioned above. in end wrote custom validator method check required value in radio button:

jquery.validator.addmethod("requiredradiovalue", function(value, element, params) {      var selectedvalue = $('input:radio[name=' + element.name + ']:checked').val();      return (typeof(params) == 'array') ? (params.indexof(selectedvalue) != -1) : selectedvalue == params; }, "you must select required option.");  

the method used e.g.

signedcif: { requiredradiovalue: 'yes' } 

the allowed options can array or single value.

hope helps, hoping wasn't straight-forward way this, alternatives gratefully received!


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -