Forum Moderators: open

Message Too Old, No Replies

Verify email

         

atteso

6:16 pm on Nov 5, 2004 (gmt 0)

10+ Year Member



I have an email field, but also want to have a verify email field in my form - which should be compared to the first email field.

What is the javascript code I need? I tride like below, but it doesn´t work. (please explain in detail - I´m not a hacker... :-)

<td>E-mail:</font><span class="style1">*</span></td>
<td>
<input name="_email" type="text" size="30">

<td>Verify e-mail:<span class="style1">*</span></font></td>
<td>
<input name="_email2" type="text" size="30">

kaled

7:28 pm on Nov 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<script type="text/javascript">
<!--
function verify()
{ with (document.forms[0]) return (email.value == email2.value)
}
// -->
</script>

<form onsubmit="return verify();">

I think the code above will do what you want.
This assumes that the email fields are in the first form of the page and that verification is required when the form is submitted

Kaled.

atteso

9:22 pm on Nov 5, 2004 (gmt 0)

10+ Year Member



Okay, Thank You.

But how can I make so that verification is required when the form is submitted?

adni18

11:46 pm on Nov 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



just like Kaled said: <form onsubmit="return verify();">

atteso

5:32 pm on Nov 6, 2004 (gmt 0)

10+ Year Member



Hmm doesn't work.

Where should I put the script - in the head or somewhere else?

Does it matter that I already have another "on submit" command?

kaled

6:14 pm on Nov 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Like any HTML attribute, onsubmit may only be specified once within a single <form> tag.

Kaled.

atteso

8:16 pm on Nov 6, 2004 (gmt 0)

10+ Year Member



Okay, so what can I do?

kaled

12:30 am on Nov 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The script may be placed in the body or the head.

I guess your form declaration will have to look something like this.


<form name="myform" onsubmit="doSomething(); doSomethingElse(); return verify();">

You might also consider buying a book on javascript if you plan to do any real coding.

Kaled.