Guest User

Untitled

a guest
Oct 24th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <form action="navigation.html" method="post" id="query-form" class="form-signin">
  2.  
  3. <input type="text" name="username" class="form-control" id="username" placeholder="Username">
  4. <input type="password" name="password" class="form-control" id="password" placeholder="Password">
  5. <button type="submit" class="btn btn-lg btn-primary btn-block" id="submit">
  6. Prisijungti
  7. </button>
  8. </form>
  9.  
  10.  
  11. <script>
  12. jQuery(document).ready(function($) {
  13. jQuery("#submit").click(function() {
  14. var username = jQuery("#username").val();
  15. var password = jQuery("#password").val();
  16. jQuery('#username, #password').removeClass("has_error");
  17. if (username === '') {
  18. jQuery('#username').addClass("has_error");
  19. return false;
  20. } else {
  21. jQuery('#username').removeClass("has_error");
  22. }
  23. if (password === '') {
  24. jQuery('#password').addClass("has_error");
  25. return false;
  26. } else {
  27. jQuery('#password').removeClass("has_error");
  28. }
  29. });
  30. });
  31. </script>
  32.  
  33. jQuery("#submit").click(function(e) {
  34. e.preventDefault();
  35. var username = jQuery("#username").val();
  36. var password = jQuery("#password").val();
  37.  
  38. //rest of code
  39.  
  40. $('#query-form').submit(); // once checks complete
  41. });
  42.  
  43. $(function() {
  44. $("#submit").click(function() {
  45. var $inputs = $(this).siblings('input'),
  46. isValid = true;
  47. $inputs.each(function() {
  48. var hasError = !$(this)[0].value.length;
  49. isValid = isValid && !hasError;
  50. $(this).toggleClass('has_error', hasError);
  51. });
  52.  
  53. return isValid;
  54. });
  55. });
Add Comment
Please, Sign In to add comment