Guest User

Untitled

a guest
Aug 26th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.65 KB | None | 0 0
  1. jquery validation plugin not working
  2. $('#buttonID').live('click', function(event) {
  3.  
  4. $('#formID').validate({
  5. rules: {
  6. firstName: "required",
  7. lastName: "required",
  8. phoneNum: {
  9. required: true,
  10. minlength: 10
  11. },
  12. pword: {
  13. required: true,
  14. minlength: 7
  15. },
  16. cpword: {
  17. required: true,
  18. minlength: 7,
  19. equalTo: "#pword"
  20. },
  21. emailId: {
  22. required: true,
  23. email: true
  24. }
  25. },
  26. messages: {
  27. firstName: "Please enter firstname",
  28. lastName: "Please enter lastname",
  29. phoneNum: "Please provide a phone number",
  30. pword: {
  31. required: "Please provide a password",
  32. minlength: "Your password must be at least 7 characters long"
  33. },
  34. cpword: {
  35. required: "Please provide a password",
  36. minlength: "Your password must be at least 7 characters long",
  37. equalTo: "Please enter the same password as above"
  38. },
  39. emailId: "Please enter a valid email address"
  40. }
  41.  
  42. });
  43.  
  44. event.preventDefault();
  45. });
  46.  
  47. function createNewUser(event){
  48. //clear all the divs
  49. if ($("#srchResults").length > 0){
  50. $('#srchResults').empty();
  51. }
  52. var htmlTable;
  53.  
  54. htmlTable = '<form id="userAttrC">';
  55. htmlTable += '<table style="border: 0px; width: 91%;" id="createUserTable" class="rec_filters">';
  56. htmlTable += '<tr><td>';
  57. htmlTable += '<input type="submit" id="saveUser" class = "buttons" value="Save" >&nbsp;<input type="submit" id="cancelUser" class = "buttons" value="Cancel" >';
  58. htmlTable += '</td></tr>';
  59. htmlTable += '<tr>';
  60. htmlTable += '<td style="width: 30%; vertical-align: top;">';
  61. htmlTable += '</td>';
  62. htmlTable += '<td style="width: 1%; text-align: center;">';
  63. htmlTable += '</td>';
  64. htmlTable += '<td style="width: 60%; text-align: left; vertical-align: top;">';
  65.  
  66. htmlTable += '<b>Personal Information</b><br />';
  67. htmlTable += '<hr class="d">';
  68. htmlTable += '<label for="salutation">Salutation:</label>';
  69. htmlTable += '<select id="salutationDD" name="salutation" class="filterselect">';
  70. htmlTable += '<option value=""></option>';
  71. htmlTable += '<option value="Mr.">Mr.</option>';
  72. htmlTable += '<option value="Ms.">Ms.</option>';
  73. htmlTable += '<option value="Mrs.">Mrs.</option></select><br />';
  74.  
  75. htmlTable += '<label for="fname">First Name:</label>';
  76. htmlTable += '<input type="text" name="fname" id="firstName" class="readOnlyIp" value="" /><br />';
  77.  
  78. htmlTable += '<label for="lname">Last Name:</label>';
  79. htmlTable += '<input type="text" name="lname" id="lastName" class="readOnlyIp" value="" /><br />';
  80.  
  81. htmlTable += '<label for="suffix">Name Suffix:</label>';
  82. htmlTable += '<input type="text" name="suffix" class="readOnlyIp" value="" /><br />';
  83.  
  84. htmlTable += '<label for="email">Email:</label>';
  85. htmlTable += '<input type="text" name="email" id="emailId" class="readOnlyIp" value="" /><br />';
  86.  
  87. htmlTable += '<label for="country">Country:</label>';
  88.  
  89. htmlTable += '<select id="countryDD" name="country" class="filterselect">';
  90.  
  91. //get country list via ajax call
  92. $.ajaxSetup({
  93. async: false,
  94. "error":function() {
  95. alert("error");
  96. }});
  97. $.getJSON("<url>",
  98. {
  99. countries: "1"
  100. },
  101. function(data) {
  102.  
  103. htmlTable += '<option value=""></option>';
  104.  
  105. for(var i=1; i<data[0].length; i++){
  106. htmlTable += '<option value="'+data[0][i]+'">'+data[0][i]+'</option>';
  107. }
  108. });
  109. htmlTable += '</select><br />';
  110.  
  111. htmlTable += '<label for="phone">Phone Number:</label>';
  112. htmlTable += '<input type="text" name="phone" id="phoneNum" class="readOnlyIp" value="" /><br />';
  113.  
  114. htmlTable += '<label for="ext">Phone Extension:</label>';
  115. htmlTable += '<input type="text" name="ext" class="readOnlyIp" value="" /><br />';
  116.  
  117. htmlTable += '<label for="cell">Cell Phone:</label>';
  118. htmlTable += '<input type="text" name="cell" class="readOnlyIp" value="" /><br />';
  119.  
  120. htmlTable += '<label for="pwd">Password:</label>';
  121. htmlTable += '<input type="text" name="pwd" id="pword" class="readOnlyIp" value="" /><br />';
  122. htmlTable += '<label for="cpwd">Confirm Password:</label>';
  123. htmlTable += '<input type="text" name="cpwd" id="cpword" class="readOnlyIp" value="" /><br />';
  124. htmlTable += '</td></tr>';
  125. htmlTable += '</table>';
  126. htmlTable += '</form>';
  127.  
  128. $('#srchResults').append(htmlTable);
  129. event.preventDefault();
  130. }
  131. $("#createUser").click(function(event){ createNewUser(event); });
  132.  
  133. $('#formID').valid();
  134.  
  135. if($('#formId').valid()){
  136. //do your form posting logic here
  137. }
  138. else{
  139. //anything special you want to do with an invalid form
  140.  
  141. }
  142.  
  143. $('#srchResults').append(htmlTable);
  144.  
  145. if($('#formId').valid()){
  146. //do your form posting logic here
  147. }
  148. else{
  149. //anything special you want to do with an invalid form
  150.  
  151. }
  152.  
  153. $('#buttonID').live('click', function(event) {
  154.  
  155. var _validator;
  156.  
  157. $(function() {
  158. _validator = $('#formID').validate({
  159. onsubmit: false,
  160. rules: { ... },
  161. messages: { ... }
  162. });
  163.  
  164. $('#buttonID').click(function(e) {
  165. e.preventDefault();
  166. if ( _validator.form() ) {
  167. // valid form code
  168. }
  169. });
  170. });
Add Comment
Please, Sign In to add comment