JQuery form validation - validate form based on other form field -


i"m using jquery form validation in basic form looks this

$('#shopping_form').validate({             submithandler: function(){   $.post("/url", { message: messageval}, function(data) {   ......   ......   }, } ,rules: {     message: { required:true },     price: { number: true  }                 } }); 

now adding 2 radio buttons form call them radio1 , radio2. if radio1 selected field message required , radio2 not required field.

how can add kind of rule. in advance

you can writing custom method checks radio button value , depending on value , checks message field. here code can add in jquery

$.validation.addrule("message",{  check: function(value) {     // check value of radio button here, can        if($("form input:radio:checked").val() == 'radio2') return true;      // radio2 checked return valid, ie. field not required field.     if(value.length > 0) {         return true;     }     return false; }, msg : "field required." }); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -