Incorporating two forms on my website, I added a button that transitions between the login and sign-up forms smoothly. The process is as follows:
- Initially, the login form is displayed; clicking the button switches to the sign-up form.
- Proceeding to submit the sign-up form causes a page reload.
- Upon reload, the login form reappears by default.
The issue arises when I desire the last active form to remain displayed even after the page refreshes.
HTML:
<section id="content">
<div id="logo" style="margin-left: 0;"></div>
<div id="container">
<form id="sign_up" action="login.php" method="post">
<table style="margin: 0px auto;">
<tr>
<td align="center"> <span style="font-weight: bold;font-size: 2em; color: Gray;">Sign Up</span>
</td>
<tr>
<td>
<input type="text" placeholder="Username" name="username" required="required" />
</td>
</tr>
<tr>
<td>
<input type="password" placeholder="Password" name="password" required="required" />
<br />
</td>
</tr>
<tr>
<td>
<input class="input" type="password" placeholder="Confirm Password" name="confirm_password" required="required" />
<br />
</td>
</tr>
<tr>
<td>
<br/>
</td>
</tr>
<tr align="right">
<td>
<input class="btn" type="submit" value="Sign Up" name="submit_sign_up">
</td>
</tr>
</table>
</form>
<form id="sign_in" action="login.php" method="post">
<table style="margin: 0 auto;">
<tr>
<td align="center"> <span style="font-weight: bold;font-size: 2em; color: Gray;">Sign In</span>
</td>
<tr>
<td>
<input class="input" type="text" placeholder="Username" name="username" required="required" />
</td>
</tr>
<tr>
<td>
<input class="input" type="password" placeholder="Password" name="password" required="required" />
<br />
</td>
</tr>
<tr>
<td>
<br/>
</td>
</tr>
<tr align="right">
<td>
<input class="btn" type="submit" value="Sign In" name="submit_sign_in">
</td>
</tr>
</table>
</form>
<br/>
<input id="sign_up_btn" class="btn" type="submit" style=" font-weight:bold; height:40px; width: 292px;" value="Create An Account"></input>
</div>
</section>
CSS:
#content {
margin-top: 10%;
}
#container {
margin: 0 auto;
width: 80%;
text-align: center;
}
input[type=text], input[type=password] {
width: 250px;
min-height: 25px;
border-radius: 3px;
border: 0;
padding: 7px;
font-family: Calibri;
font-size: 20px;
box-shadow: 0px 0px 3px 1px #aaa inset;
box-sizing: border-box;
}
#sign_in, #sign_up {
border: 1px solid #4f4f4f;
border-radius: 10px;
margin: 0 auto;
height: 200px;
width: 292px;
padding: 10px;
background-color: #eee;
border: 0px;
box-shadow: 0px 0px 15px 1px #000;
}
#sign_up {
display: none;
height: 250px;
}
JS:
jQuery(function ($) {
var $sUp = $("#sign_up"),
$sIn = $("#sign_in");
$("#content").on('click', "#sign_up_btn", function () {
$sIn.stop().fadeOut(800, function () {
$sUp.fadeIn(800);
});
$(this).stop().fadeOut(800, function () {
$(this).attr({
value: "Already have an account?",
id: "sign_in_btn"
}).fadeIn(800);
});
}).on('click', "#sign_in_btn", function () {
$sUp.stop().fadeOut(800, function () {
$sIn.fadeIn(800);
});
$(this).stop().fadeOut(800, function () {
$(this).attr({
value: "Create An Account",
id: "sign_up_btn"
}).fadeIn(800);
});
});
});