Advertisement
firoze

Form Validation By Switch Case

Mar 21st, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     <form name="frm" onClick="return formValid(this)">
  2.         <table>
  3.             <tr>
  4.                 <td>Form Validation By Switch Case</td>
  5.             </tr>
  6.             <tr>
  7.                 <td>
  8.                     <input type="text" name="name" placeholder="Name"/>
  9.                     <span id="showTextName"></span>
  10.                 </td>
  11.             </tr>
  12.             <tr>
  13.                 <td>
  14.                     <input type="text" name="email" placeholder="Email"/>
  15.                     <span id="showTextEmail"></span>
  16.                 </td>
  17.             </tr>
  18.             <tr>
  19.                 <td>
  20.                     <input type="text" name="password"/>
  21.                     <span id="showTextPass"></span>
  22.                 </td>
  23.             </tr>
  24.             <tr>
  25.                 <td>
  26.                     <input type="submit" value="submit"/>
  27.                 </td>
  28.             </tr>
  29.         </table>
  30.     </form>
  31.  
  32. <script>
  33.     function formValid(process){
  34.         with(document.frm) // short in method of form name in javascript
  35.         switch(process){
  36.             case document.frm:
  37.                 if(name.value == ""){
  38.                     document.getElementById('showTextName').innerHTML = "Please Enter Your Name";
  39.                     name.select();
  40.                     return false;
  41.                 }
  42.                 if(email.value == ""){
  43.                     document.getElementById('showTextEmail').innerHTML = "Please Enter Your Email";
  44.                     email.select();
  45.                     return false;
  46.                 }
  47.                 if(password.value == ""){
  48.                     document.getElementById('showTextPass').innerHTML = "Please Enter Your Password";
  49.                     password.select();
  50.                     return false;
  51.                 }
  52.                 break;
  53.            
  54.         }
  55.     }
  56. </script>
  57.  
  58. <style type="text/css">
  59.     #showTextName,#showTextEmail,#showTextPass{
  60.         color:red;
  61.     }
  62. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement