javascript - validate login & redirect to success page using jquery validate plugin -


i new advance level of jquery scripting , here using jquery validation login page.

if login page success has redirect success page code working fine below code when click submit button .

<form id="form1" name="login" method="post" action="mainpage.html">  </form> 

here code

$(function (){      $("#form1").validate({     // specify validation rules     rules: {         username: {             required: true,             email: true         },         password: {             required: true,             minlength: 5         }     },      // specify validation error messages     messages: {         username: "please enter valid email address",         password: {             required: "please provide password",             minlength: "your password must @ least 5 characters long"         },           submithandler: function (form) { // demo                          $('#username').focus();                          $('#submit').click(function () {                              event.preventdefault(); // prevent pagereload                                                              var valemail = $('#username').val() === 'admin@admin.com'; // email value                              alert("email" + valemail);                              var valpassword = $('#password').val() === 'admin1234'; // password value                              if (valemail === true && valpassword === true) { // if valemail & val valpass above                                  alert('valid!'); // alert valid!                                  window.location.href = "http://java67.blogspot.com";                                  // go home.html                              }                              else {                                  alert('not valid!'); // alert not valid!                              }                          });                      }     } });  }); 

but need validation example if emailid = admin@admin.com & passsword = admin1234 when click submit needs check whether emailid john@xyz.com , passsword password if both successful has redirect, else has show error message in label.

now getting error http error 405.0 - method not allowed

here fiddle link

thanks in advance

regards m

your code broken following reasons...

1) you've incorrectly placed success option inside of messages option. success option sibling of messages, not child.

messages: {     username: "please enter valid email address",     password: {         required: "please provide password",         minlength: "your password must @ least 5 characters long"     },     success: function (data) {  // <- not belong inside of 'messages' option         ....     } } 

2) as per documentation, success options for: "if specified, error label displayed show valid element." in other words, use success if want error label shown when there no error; green checkmark effect.

3) success function has nothing intended purpose of success option. what's point of using validation plugin if you're going manually write validation function? see comments.

success: function (data) {     if (username == 'john@xyz.com' && password == password) { // plugin automatically when evaluates rules         window.location = "mainpage.html"; // 'action' part of '<form>'     }     else {         $('#username').focus();  // again, plugin this.     } } 

simply let plugin operate designed...

  • when validation fails, you'll message , field come focus.

  • when validation passes, form submit , redirect mainpage.html url specified action="mainpage.html" attribute of <form>.

your jsfiddle updated...

http://jsfiddle.net/sparky672/ny9bt1ak/3/


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -