Jquery dom is very powerful to manipulate dom elements in your web application. In this tutorial i will show you how to use jquery dom in login or signup form example.
in the pictures below you should notice the differences. When “I have an account” is selected, it wants you to login by typing your password and click Submit button. In another side if “I am new” is selected the application wants you to signup by typing your new password and click Signup button.
Using PHP and Jquery especially jquery dom, it is easy to be achieved.
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<html> <head> <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#login").click(function(){ $("#newpassword").val(""); $("#signup_block").hide(); $("#login_block").show(); }); $("#signup").click(function(){ $("#password").val(""); $("#login_block").hide(); $("#signup_block").show(); }); }); </script> </head> <body> <form type="post" method="login.php"> <div> <label>Email</label> <br/> <input type="text" name="email"/><br /> <input type="radio" name="choose" id="login" checked="checked"/> I have an account <br /> <input type="radio" name="choose" id="signup"/> I am new!<br /> </div> <div id="login_block"> <label>Password</label><br /> <input type="password" name="password" id="password"/><br/> <input type="submit" value=" Login "/> </div> <div id="signup_block" style="display:none"> <label>Choose password</label><br/> <input type="password" name="newpassword" id="newpassword" /><br/> <input type="submit" value=" Signup "/> </div> </form> </body> </html> |
login.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php if($_POST){ $email = $_POST['email']; $password = $_POST['password']; $newpassword = $_POST['newpassword']; if($_POST['password'] && $_POST['email']){ $sql=mysql_query("SQl select statement"); echo "Login success"; } else if($_POST['newpassword'] && $_POST['email']){ $sql=mysql_query("SQl Insert values statement"); echo "Registration Success"; } } ?> |
Facebook Comments