Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking emails match

Status
Not open for further replies.

sophielois

Technical User
Sep 8, 2005
66
0
0
GB
Hi,

im trying to make sure that users input there correct email address by asking them to enter it twice and checking that what they have entered matches. If they have entered it incorrectly twice well hey what can i say.... anyway this is all i have at the minute, ive never attempted to do this so any advice would be grand!!

form:
Code:
<table class="contact" style="width:297px; margin-left:0px;" cellpadding="5" cellspacing="0" id="form">
            <form method="POST" action="subscribe.php" name="form">
              <tr> 
                <td width="54%" valign="middle"> Full Name:</td>
                <td width="46%"  align="right" valign="middle"> <input name="fullname" type="text" id="fullName11"> 
                </td>
              </tr>
              <tr> 
                <td valign="middle"> Email Address:</td>
                <td align="right" valign="middle"> <input name="email" type="text" id="emailll" ></td>
              </tr>
              <tr> 
                <td valign="middle"> Confirm Email Address</td>
                <td align="right" valign="middle"> <input name="email1" type="text" id="email1" ></td>
              </tr>
              <tr> 
                <td> </td>
                <td align="right"> <div align="right"> 
                    <input type="submit" name="Submit2" value="Subscribe" onClick="return validate(form)">
                  </div></td>
              </tr>
            </form>
          </table>

validation script
Code:
<script language="JavaScript"> 
<!-- 
function validate(form) { 
    if (form.fullname.value.length == 0) 
    { 
        alert("Please enter your full name.") 
        form.fullname.focus() 
        return false 
    } 

    if (form.email.value.length == 0) 
    { 
        alert("Please enter your e-mail address.") 
        form.email.focus() 
        return false 
    } 

    if (form.email.value.indexOf("@") == -1) 
    { 
        alert("Please enter a valid e-mail address."); 
        form.email.focus(); 
        return false; 
    } 


} 
//--> 
</script>

ta Soph
 
add this:

Code:
    if (form.email.value != form.email1.value)
    {
        alert("The emails must match!");
        form.email.focus();
        return false;
    }

and instead of calling the function in your onclick event, call it like this:

Code:
<form ... onsubmit="return validate(this);">

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Thanks cLFlaVA and others thats great

Soph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top