0

I have two buttons Sign-in and Register. Sign-in button shows login form and register button shows register form when clicked. What I want is to change the url without refreshing the page so if I click register it should change url to register same to the login. So far when I click the register button it change the url but when I click the login it doesn't change to login url it keeps showing the register url how can I fix this?

Html

   <li class="signin-active"><a class="btn">Log in</a></li>
   <li class="signup-inactive"><a class="btn">Sign up </a></li>


    <div ng-app ng-init="checked = false">

     <form class="form-signin" action="" method="post" name="form">
      <label for="username">Username</label>
      <input class="form-styling" type="text" name="username" placeholder=""/>
      <label for="password">Password</label>
      <input class="form-styling" type="text" name="password" placeholder=""/>
      <input type="checkbox" id="checkbox"/>
      <label for="checkbox" ><span class="ui"></span>Remember me</label>
      <div class="btn-animate">
        <a class="btn-signin">Sign in</a>
      </div>
    </form>

          
         <form class="form-signup" action="" method="post" name="form">
           <label for="fullname">Full name</label>
           <input class="form-styling" type="text" name="fullname" placeholder=""/>
           <label for="email">Email</label>
           <input class="form-styling" type="text" name="email" placeholder=""/>
           <label for="password">Password</label>
           <input class="form-styling" type="text" name="password" placeholder=""/>
           <label for="confirmpassword">Confirm password</label>
           <input class="form-styling" type="text" name="confirmpassword" placeholder=""/>
           <a ng-click="checked = !checked" class="btn-signup">Sign Up</a>
         </form>
   </div>

Javascript

  <script>
  $(function() {
    var url = '{{ route('register') }}';
    var url1 = '{{ route('login') }}';

    $(".btn").click(function() {
    $(".form-signin").toggleClass("form-signin-left");
    $(".form-signup").toggleClass("form-signup-left");
    $(".signup-inactive").toggleClass("signup-active");
    $(".signin-active").toggleClass("signin-inactive");
        window.history.pushState('null', 'null', url);
    });
});
</script>

1 Answer 1

1
window.history.pushState('null', 'null', url);

This is always pushing url to the history. You need to change your code to push url1 (login) if the user is already on the register page.

I would recommend doing this by separating two different click handlers Add the class "login-btn" to your login button and use $(".login-btn").click(function() { to handle that, and the same approach for your register button

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.