Advertisement
CastelShal

Web Prac 5

Aug 20th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #index.php
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <title>Login Page</title>
  6. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  7. <script src="script.js"></script>
  8. </head>
  9. <body>
  10. <h1>Login Page</h1>
  11. <form id="loginForm" action="login.php" method="post">
  12. <div style="padding:5px">
  13. <label for="username">Username:</label>
  14. <input type="text" id="username" name="username">
  15. <span class="error" id="usernameError"></span>
  16. </div>
  17. <div style="padding:5px">
  18. <label for="password">Password:</label>
  19. <input type="password" id="password" name="password">
  20. <span class="error" id="passwordError"></span>
  21. </div>
  22. <div style="padding:5px">
  23. <label for="check"></label>
  24. <input type="checkbox" id="check" name="agree">I agree to the Terms and conditions
  25. <span class="error" id="checkError"></span>
  26. </div>
  27. <div style="padding:5px">
  28. <button type="submit">Login</button>
  29. </div>
  30. </form>
  31. </body>
  32. </html>
  33.  
  34. #script.js
  35. $(document).ready(function(){
  36. $("#loginForm").submit(function(event){
  37. var username= $("#username").val();
  38. var password= $("#password").val();
  39. var check= $("#check").prop("checked");
  40. console.log(check);
  41. //.val extracting the user input and assigning it to the username and password variables
  42. var valid= true;
  43.  
  44. //Clear previous error messages
  45. $(".error").text("");
  46.  
  47. //Validate username
  48. //=== checking the value and data type
  49. if (username ===""){
  50. $("#usernameError").text("Username is required.");
  51. valid = false;
  52. }
  53.  
  54. //Validate password
  55. if (password ===""){
  56. $("#passwordError").text("Password is required.");
  57. valid = false;
  58. }
  59.  
  60. #login.php
  61. <?php echo "success";>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement