Fredin

Untitled

May 31st, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkForm()
  2. {
  3.     preventDefault();
  4.    
  5.     var nameValue = document.forms["theForm"]["username"].value;
  6.     var passValue = document.forms["theForm"]["password"].value;
  7.    
  8.     var correctName = false;
  9.     var correctPass = false;
  10.        
  11.         if(nameValue=="")
  12.         {
  13.             theForm.username.style.backgroundColor = "red";
  14.         }
  15.         if(passValue=="")
  16.         {
  17.             theForm.password.style.backgroundColor = "red";
  18.         }
  19.         if(!nameValue=="")
  20.         {
  21.             theForm.username.style.backgroundColor = "white";
  22.             correctName = true;
  23.         }
  24.         if(!passValue=="")
  25.         {
  26.             theForm.password.style.backgroundColor = "white";
  27.             correctPass = true;
  28.         }
  29.         if (correctName && correctPass)
  30.             {
  31.                 //alert("Testtest");
  32.                 //clearForm(theForm);
  33.                 return this;
  34.             }
  35. }
  36.  
  37. function preventDefault(e)
  38. {
  39.     if(e && e.preventDefault)//Mozilla
  40.     {
  41.         e.preventDefault();
  42.     }
  43.     if(window.event)//IE
  44.     {
  45.         window.event.returnValue = false;
  46.     }
  47. }
  48.  
  49. function clearForm(ele)
  50. {
  51.     $(ele).find(':input').each(function()
  52.         {
  53.         switch(this.type)
  54.         {
  55.             case 'select-one':
  56.             case 'password':
  57.             case 'text':
  58.                 $(this).val('');
  59.                 break;
  60.             case 'radio':
  61.                 this.checked = false;
  62.         }
  63.     });
  64. }
Advertisement
Add Comment
Please, Sign In to add comment