Advertisement
Guest User

BETLOG WARREN

a guest
Nov 12th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1.  
  2. $(document).ready(function(){
  3.  
  4.  
  5.  
  6.  
  7. // validate signup form on keyup and submit
  8. setFormValidation('#createForm');
  9. setFormValidation('#editForm');
  10.  
  11. $("#createForm").submit(function(e) {
  12. e.preventDefault(); // [prevents submitting form to do ajax]
  13. });
  14. $("#editForm").submit(function(e) {
  15. e.preventDefault();// [prevents submitting form to do ajax]
  16. });
  17.  
  18. function setFormValidation(id) {
  19. $(id).validate({
  20. highlight: function(element) {
  21. $(element).closest('.form-group').removeClass('has-success').addClass('has-danger');
  22. },
  23. success: function(element) {
  24. $(element).closest('.form-group').removeClass('has-danger').addClass('has-success');
  25. },
  26. errorPlacement: function(error, element) {
  27. $(element).closest('.form-group').append(error);
  28. },
  29. });
  30. }
  31.  
  32.  
  33.  
  34.  
  35. ///////////////
  36.  
  37. AJAX FUNCTION
  38.  
  39. function createSave(){
  40.  
  41. if($("#createForm").valid()){ ---> checking if all fields are valid
  42.  
  43.  
  44. ////
  45. MODAL EXAMPLE
  46.  
  47.  
  48.  
  49.  
  50. <div class="modal fade " tabindex="-1" role="dialog" id="editAccount">
  51. <div class="modal-dialog modal-lg" role="document" >
  52. <div class="modal-content">
  53. <form id="editForm" role="form" method="post" accept-charset="utf-8" >
  54. <div class="modal-header">
  55. <h3 class="modal-title">Account Details</h3>
  56. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  57. <span aria-hidden="true">&times;</span>
  58. </button>
  59. </div>
  60. <div class="modal-body">
  61.  
  62. <div class="row">
  63. <div class="col-md-6">
  64. <div class="form-group">
  65. <label>Firstname</label>
  66. <input type="text" class="form-control" name="firstname" id="efirstname" placeholder="Enter Firstname" required>
  67. </div>
  68. </div>
  69. <div class="col-md-6">
  70. <div class="form-group">
  71. <label>Lastname</label>
  72. <input type="text" class="form-control" name="elastname" id="elastname" placeholder="Enter Lastname" required>
  73. </div>
  74. </div>
  75. <div class="col-md-12">
  76. <div class="form-group">
  77. <label>Student Number</label>
  78. <input type="text" class="form-control" name="estudentNumber" id="estudentNumber" placeholder="Enter Student Number" minlength="8" required>
  79. </div>
  80. </div>
  81. <div class="col-md-6">
  82. <div class="form-group">
  83. <label>Contact Number</label>
  84. <input type="text" class="form-control" name="econtact" id="econtact" placeholder="Enter Contact Number" required>
  85. </div>
  86. </div>
  87. <div class="col-md-12">
  88. <div class="form-group">
  89. <label>Email</label>
  90. <input type="email" class="form-control" name="eemail" id="eemail" placeholder="Enter Email Address" required>
  91. </div>
  92. </div>
  93. <div class="col-md-12">
  94. <div class="form-group">
  95. <label>Program</label>
  96. <select id="eprogram" name="eprogram" class="form-control" required>
  97. <option value ="">---</option>
  98. <option value="1">Bachelor of Science in Computer Science Major in Application Development</option><option value="2">Bachelor of Science in Information Technology in Service Management</option><option value="3">Bachelor of Science in Computer Network Administration</option><option value="4">Bachelor of Science in Information Technology Major in Information Network Security</option><option value="5">Bachelor of Science in Computer Science Major in Social Computing</option><option value="6">Bachelor of Science in Computational & Data Sciences</option><option value="7">Diploma in Application Development</option><option value="8">Diploma in Computer Network Administration</option><option value="9">Not Set</option> </select>
  99. </div>
  100. </div>
  101. <div class="col-md-6">
  102. <div class="form-group">
  103. <label>Year</label>
  104. <select id="eyear" name="eyear" class="form-control" required>
  105. <option value="1">First Year</option><option value="2">Second Year</option><option value="3">Third Year</option><option value="4">Fourth Year</option><option value="5">Not Set</option> </select>
  106. </div>
  107. </div>
  108. <div class="col-md-6">
  109. <div class="form-group">
  110. <label>Section</label>
  111. <select id="esection" name="esection" class="form-control" required>
  112. <option value ="0">---</option>
  113. </select>
  114. </div>
  115. </div>
  116.  
  117.  
  118. </div>
  119.  
  120.  
  121. <input type="hidden" name="eid" id="eid">
  122.  
  123.  
  124. </div>
  125. <div class="modal-footer">
  126. <button type="submit" class="btn btn-primary" type="submit" onclick='editSave();'>Save Changes</button>
  127. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  128. </div>
  129.  
  130. </form>
  131. </div>
  132. </div>
  133. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement