Guest User

Untitled

a guest
Dec 11th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <form id="theForm" class="formContainer">
  2. <div class="formbox formbox-33">
  3. <input type="text" name="FirstName" class="inputField required">
  4. <label class="float-label">First Name:</label>
  5. </div>
  6. <button type="Submit" id="submitButton">Submit</button>
  7. </form>
  8.  
  9. <form id="theForm2" class="formContainer">
  10. <div class="formbox formbox-33">
  11. <input type="text" name="FirstName" class="inputField required">
  12. <label class="float-label">First Name:</label>
  13. </div>
  14. <button type="Submit" id="submitButton">Submit</button>
  15. </form>
  16.  
  17. <script type="text/javascript">
  18. $(document).ready(function() {
  19. // Initializing the forms present on current page
  20. $("#theForm").validate();
  21. $("#theForm2").validate();
  22. });
  23. </script>
  24.  
  25. var $theForm = $(".formContainer"),
  26. $form = $theForm.validate();
  27.  
  28. $theForm.on('blur', '.inputField', function(e){
  29. if( $(this).hasClass("errorMessage") && $(this).parent().not( "invalid" ) ) {
  30. $( this ).parent().addClass(" invalid");
  31. $( this ).parent().removeClass("inputValid");
  32. }
  33. if( $(this).hasClass("valid") ) {
  34. $( this ).parent().addClass(" inputValid");
  35. $( this ).parent().removeClass("invalid");
  36. }
  37. });
  38.  
  39. $( ".button-reset" ).click(function() {
  40.  
  41. var parentFinder = '#' + $(this).parents('.formContainer').attr("id");
  42. var $FormReseter = $(parentFinder).validate();
  43. $FormReseter.resetForm();
  44. $(parentFinder + " .inputValid").removeClass("inputValid");
  45. $(parentFinder + " .invalid").removeClass("invalid");
  46.  
  47. });
  48.  
  49. $(".formContainer").each(function(i, obj) {
  50. $form = $(this).validate();
  51. $(this).on('blur', '.inputField', function(e){
  52. if( $(this).hasClass("errorMessage") && $(this).parent().not( "invalid" ) ) {
  53. $( this ).parent().addClass(" invalid");
  54. $( this ).parent().removeClass("inputValid");
  55. }
  56. if( $(this).hasClass("valid") ) {
  57. $( this ).parent().addClass(" inputValid");
  58. $( this ).parent().removeClass("invalid");
  59. }
  60. });
  61. });
Add Comment
Please, Sign In to add comment