Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="html_form_send.php" name="myForm" onsubmit="return(validate());" method="post">
- <table cellspacing="2" cellpadding="2" border="1">
- <tbody>
- <tr>
- <td align="right">First Name*</td>
- <td><input type="text" name="firstname" /></td>
- </tr>
- <tr>
- <td align="right">Last Name*</td>
- <td><input type="text" name="lastname" /></td>
- </tr>
- <tr>
- <td align="right">Email *</td>
- <td><input type="text" name="email" /></td>
- </tr>
- <tr>
- <td align="right">Confirm Email *</td>
- <td><input type="text" name="confirmation_email" /></td>
- </tr>
- <tr>
- <td align="right">Comment *</td>
- <td><textarea name="Comment" cols="25" rows="6"></textarea></td>
- </tr>
- <tr>
- <td align="right"></td>
- <td><input type="submit" value="Submit" /></td>
- </tr>
- </tbody>
- </table>
- </form>
- <script type="text/javascript">// <![CDATA[
- function validateEmail()
- {
- var emailID = document.myForm.email.value;
- atpos = emailID.indexOf("@");
- dotpos = emailID.lastIndexOf(".");
- if (atpos < 1 || ( dotpos - atpos < 2 ))
- {
- alert("Please enter correct email address")
- document.myForm.email.focus() ;
- return false;
- }
- return( true );
- }
- // ]]></script>
- <script type="text/javascript">// <![CDATA[
- // Form validation code will come here.
- function validate()
- {
- if( document.myForm.firstname.value == "" )
- {
- alert( "Please provide your first name!" );
- document.myForm.firstname.focus() ;
- return false;
- }
- if( document.myForm.lastname.value == "" )
- {
- alert( "Please provide your last name!" );
- document.myForm.lastname.focus() ;
- return false;
- }
- if( document.myForm.email.value == "" )
- {
- alert( "Please provide your Email!" );
- document.myForm.email.focus() ;
- return false;
- }else{
- var ret = validateEmail();
- if( ret == false )
- {
- return false;
- }
- }
- if( document.myForm.confirmation_email.value == "" )
- {
- alert( "Please provide your Email!" );
- document.myForm.confirmation_email.focus() ;
- return false;
- }else if (document.myForm.email.value != document.myForm.confirmation_email.value){
- alert( "Please enter the same email address!" );
- document.myForm.confirmation_email.focus() ;
- return false;
- }
- if( document.myForm.Comment.value == "" )
- {
- alert( "Please provide your Comment!" );
- document.myForm.Comment.focus() ;
- return false;
- }
- return( true );
- }
- // ]]></script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement