Advertisement
Guest User

HTML Form

a guest
Apr 16th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.81 KB | None | 0 0
  1.    
  2.  
  3.     <form action="html_form_send.php" name="myForm" onsubmit="return(validate());" method="post">
  4.     <table cellspacing="2" cellpadding="2" border="1">
  5.     <tbody>
  6.     <tr>
  7.     <td align="right">First Name*</td>
  8.     <td><input type="text" name="firstname" /></td>
  9.     </tr>
  10.     <tr>
  11.     <td align="right">Last Name*</td>
  12.     <td><input type="text" name="lastname" /></td>
  13.     </tr>
  14.     <tr>
  15.     <td align="right">Email *</td>
  16.     <td><input type="text" name="email" /></td>
  17.     </tr>
  18.     <tr>
  19.     <td align="right">Confirm Email *</td>
  20.     <td><input type="text" name="confirmation_email" /></td>
  21.     </tr>
  22.     <tr>
  23.     <td align="right">Comment *</td>
  24.     <td><textarea name="Comment" cols="25" rows="6"></textarea></td>
  25.     </tr>
  26.     <tr>
  27.     <td align="right"></td>
  28.     <td><input type="submit" value="Submit" /></td>
  29.     </tr>
  30.     </tbody>
  31.     </table>
  32.     </form>
  33.     <script type="text/javascript">// <![CDATA[
  34.    function validateEmail()
  35.    {
  36.    
  37.      var emailID = document.myForm.email.value;
  38.      atpos = emailID.indexOf("@");
  39.      dotpos = emailID.lastIndexOf(".");
  40.      if (atpos < 1 || ( dotpos - atpos < 2 ))
  41.      {
  42.          alert("Please enter correct email address")
  43.          document.myForm.email.focus() ;
  44.          return false;
  45.      }
  46.      return( true );
  47.    }
  48.    // ]]></script>
  49.     <script type="text/javascript">// <![CDATA[
  50.    // Form validation code will come here.
  51.    
  52.    function validate()
  53.    {
  54.    
  55.      if( document.myForm.firstname.value == "" )
  56.      {
  57.        alert( "Please provide your first name!" );
  58.        document.myForm.firstname.focus() ;
  59.        return false;
  60.      }
  61.    
  62.      if( document.myForm.lastname.value == "" )
  63.      {
  64.        alert( "Please provide your last name!" );
  65.        document.myForm.lastname.focus() ;
  66.        return false;
  67.      }
  68.    
  69.      if( document.myForm.email.value == "" )
  70.      {
  71.        alert( "Please provide your Email!" );
  72.        document.myForm.email.focus() ;
  73.        return false;
  74.      }else{
  75.        var ret = validateEmail();
  76.        if( ret == false )
  77.        {
  78.           return false;
  79.        }
  80.      }
  81.    
  82.      if( document.myForm.confirmation_email.value == "" )
  83.      {
  84.        alert( "Please provide your Email!" );
  85.        document.myForm.confirmation_email.focus() ;
  86.        return false;
  87.      }else if (document.myForm.email.value != document.myForm.confirmation_email.value){
  88.        alert( "Please enter the same email address!" );
  89.        document.myForm.confirmation_email.focus() ;
  90.        return false;
  91.      }
  92.    
  93.      if( document.myForm.Comment.value == "" )
  94.      {
  95.        alert( "Please provide your Comment!" );
  96.        document.myForm.Comment.focus() ;
  97.        return false;
  98.      }
  99.      return( true );
  100.    }
  101.    // ]]></script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement