Click to See Complete Forum and Search --> : Confirm you email address


pj&b
10-27-2003, 09:16 AM
I'm trying to confirm that the email address and confirm email address are the same. I have enter this code but it always come back with the error message even when the email and confirm email address are the same.

<script language="javascript" type="text/javascript">
function Compare(Email1, Email2)
{if (FrontPage_Form1.Email1.value == FrontPage_Form1.Email2.value)
{return true;}
else
{ alert("Your Email Address and Confirm Email Address must be the same.");
return false;}

}
</script>
</head>
in the body i have the onsubmit:

<FORM onsubmit ="Compare (Email1, Email2)" language="JavaScript" METHOD="POST" ACTION="--WEBBOT-SELF--" name="FrontPage_Form1">

It should compare the two to make sure they are the same and move on to creating the email and confirmation page. If I don't check the two email address just send the email and create the confirmaiton page everything works. Well I mean they can enter two different email but the email goes out and the confirmation page is created.

PLEASE Help. This is my first page.

Gollum
10-27-2003, 09:28 AM
by the looks of things,

Email1 and Email2 are text boxes inside your form.

The problems I can see are...

where you say onsubmit="Compare(Email1,Email2);", The terms Email1 and Email2 don't mean anything by themselves. You might try "Compare(this.Email1,this.Email2)" or "Compare(FrontPage_Form1.Email1,FrontPage_Form1.Email2)"

in your function Compare(Email1,Email2), you don't actually use the two arguments at all (even though you have FrontPage_Form1.Email1.value, etc) so the function is probably not acting the way you think it is (although it will probably work due to the coincidental fact that the element names are the same. You could change the first line to

if (Email1.value == Email2.value)

pj&b
10-27-2003, 09:48 AM
Ok I've changed the onsubmit to include the
onsubmit ="Compare(FrontPage_Form1.Email1, FrontPage_Form1.Email2)"

Are you saying next that:
function Compare(FrontPage_Form1.Email1, FrontPage_Form1.Email2)

should be more like

function Compare(this).

and the code below the function:
{if (Email1.value == Email2.value)
{return true;}
else
{ alert("Your Email Address and Confirm Email Address must be the same.");
return false;}

}
</script>
</head>

This still comes back with an error when the two emails are the same. Sorry I know it's hard to work with people new to this. But thank you I've worked all week end.

Charles
10-27-2003, 01:23 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>

<script type="text/javascript">
<!--
String.prototype.isEmailAddress = function () {return this.match(/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/)}
// -->

function verify (form) {if (form.address.value != form.confirm.value) {alert('The two addresses do not match.'); return false}}
</script>

<form action="" onsubmit="return verify(this)">
<div>
<label>Email Address<input name="address" type="text" onchange="if (!this.value.isEmailAddress()) {alert('That would not appear to be a valid email address.'); this.value=''; this.focus()}"></label>
<label>Confirm Address<input name="confirm" type="text" onchange="if (!this.value.isEmailAddress()) {alert('That would not appear to be a valid email address.'); this.value=''; this.focus()}"></label>
<button type="submit">Submit</button>
</div>
</form>

Jonathan
10-27-2003, 10:14 PM
Originally posted by Charles
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>

<script type="text/javascript">
<!--
String.prototype.isEmailAddress = function () {return this.match(/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/)}
// -->

function verify (form) {if (form.address.value != form.confirm.value) {alert('The two addresses do not match.'); return false}}
</script>

<form action="" onsubmit="return verify(this)">
<div>
<label>Email Address<input name="address" type="text" onchange="if (!this.value.isEmailAddress()) {alert('That would not appear to be a valid email address.'); this.value=''; this.focus()}"></label>
<label>Confirm Address<input name="confirm" type="text" onchange="if (!this.value.isEmailAddress()) {alert('That would not appear to be a valid email address.'); this.value=''; this.focus()}"></label>
<button type="submit">Submit</button>
</div>
</form>

you are truely crazy, where did you come up with that?!?! and can you explain it to me please :) really... I don't know the first thing about that script, and I love javascript.