Advertisement
Guest User

Untitled

a guest
Aug 14th, 2014
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     $(“#userForm”).submit(function(e) {
  3.         removeFeedback();
  4.         var errors = validateForm();
  5.         if (errors == “”) {
  6.             return true;
  7.         } else {
  8.             provideFeedback(errors);
  9.             e.preventDefault();
  10.             return false;
  11.         }
  12.     });
  13.     function validateForm() {
  14.         var errorFields = new Array();
  15.         //Check required fields have something in them
  16.         if ($(‘#name’).val() == “”) {
  17.             errorFields.push(‘name’);
  18.         }
  19.         if ($(‘#email’).val() == “”) {
  20.             errorFields.push(‘email’);
  21.         }
  22.         if ($(‘#password1’).val() == “”) {
  23.             errorFields.push(‘password1’);
  24.         }
  25.  
  26.         return errorFields;
  27.         } //end function validateForm
  28.  
  29. function provideFeedback(incomingErrors) {
  30.     for (var i = 0; i < incomingErrors.length; i++)
  31.     {
  32.         $(“#” + incomingErrors[i]).
  33.         addClass(“errorClass”);
  34.         $(“#” + incomingErrors[i] + “Error”).
  35.         removeClass(“errorFeedback”);
  36.     }
  37.     $(“#errorDiv”).html(“Errors encountered”);
  38. }
  39. function removeFeedback() {
  40.     $(“#errorDiv”).html(“”);
  41.     $(‘input’).each(function() {
  42.         $(this).removeClass(“errorClass”);
  43.     });
  44.     $(‘.errorSpan).each(function() {
  45.         $(this).addClass(“errorFeedback”);
  46.     });
  47. }
  48. });
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement