jquery - Move to second form after first form validation javascript -


i not sure wrong code. using 2 forms in jquery mobile , upon validation of first, when anchor tag clicked, if validation successful, go form 2 on #page2 or if validation fails, stay on current page. problem if data on first form correct, can navigate second form if isnt correct, event.preventdefault() gets fired , if fill form in correctly, wouldnt let me go form 2.

<form action="#" method="post" data-ajax="false">  <span class="error_form" id="username_error"></span> <label for="username">username : <span></span></label> <input type="text" name="username" id="username" placeholder="enter username"     value="">  <span class="error_form" id="password_error"></span> <label for="password">create password : <span></span></label> <input type="password" name="password" id="password" placeholder="enter password">  <span class="error_form" id="password_error_confirmation"></span> <label for="passwordagain">confirm password : <span></span></label> <input type="password" name="password_confirmation" id="password_confirmation" placeholder="enter password again">  <div class="ui-grid-a">             <div class="ui-block-a"> <a href="#" data-role="button" data-icon="arrow-l" data-iconpos="left" data-transition="pop">back</a> </div>             <div class="ui-block-b"> <a href="#page3"  id="register1" data-role="button" data-icon="arrow-r" data- iconpos="right" data-transition="pop">next</a> </div>         </div>   </form>   script.js, have tried event.preventdefault() , doent work  $('a#register1').click(function(event){       check_username();     check_password();     check_password_confirmation();       if(error_username == false && error_password == false && error_password_confirmation == false){         sessionstorage.setitem("username", $("#username").val());         sessionstorage.setitem("password", $("#password").val());         sessionstorage.setitem("password_confirmation", $("#password_confirmation").val());           $(this).attr("href", "#page3");        }else{          $(this).removeattr("href");       }  }); 

  $('a#register1').click(function(event){        check_username();     check_password();     check_password_confirmation();       if(error_username == false && error_password == false &&      error_password_confirmation == false){         sessionstorage.setitem("username", $("#username").val());         sessionstorage.setitem("password", $("#password").val());         sessionstorage.setitem("password_confirmation", $("#password_confirmation").val());          $('a#register1').attr("http://depressionapp1.westeurope.cloudapp.azure.com/register.html#page3");          //window.location.href="http://depressionapp1.westeurope.cloudapp.azure.com/register.html#page3";       }else{         $('a#register1').removeattr("href");     }  });  //this new code still not direct me page3 

Comments