javascript - validate a form before it get submitted -


this question has answer here:

i have form in jsp page. submit form using ajax. not use submit type button, use button type button call javascript function includes ajax . call javascript function on above mentioned button click. need validate form. use jquery form validation here. use function validate form.

$(function(){                   $("#detailform").validate({                      rules:{                          regdate:{                              required:true                          },                          agreementno:{                              required:true                          },                          customername:{                              required:true                          },                          customeraddress:{                              required:true                          },                          customernic:{                              required:true                          },                          telephoneno:{                              required:true                          },                          jobdescription:{                              required:true                          }                       }                  });               }); 

now cannot figure out how validate form before submit it. above function cannot called in way this.

$("#btn1").on('click',function(){                        $("#detailform").validate({                           rules:{                              regdate:{                                  required:true                              },                              agreementno:{                                  required:true                              },                              customername:{                                  required:true                              },                              customeraddress:{                                  required:true                              },                              customernic:{                                  required:true                              },                              telephoneno:{                                  required:true                              },                              jobdescription:{                                  required:true                              }                           }                      });                }); 

they call validate function on submit type button click.

so how can this. need validate function , call javascript includes ajax on button type button click. me in case. thank you!

you need define rules upon load. upon button click, can use valid() method check forms' state.

$("#btn1").on('click',function(){     if ($("#detailform").valid()) {         // form fine, send data needed     }     else {         // form not valid. messages should have been shown.     } }); 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -