comparing two text boxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    #1

    comparing two text boxes

    Be kind to me as I'm not very clever on this sort of thing , however I'm
    okay
    on basic html .

    I have a script below which I got from a free source.

    I need a way to check the first address is the same as the second
    one entered, and post an alert if not.

    I hope you understand what I'm aiming at? Thanks in advance of any help

    Steve
    =============== =============== =============== =============== ==
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    </HEAD>

    <! Form Processing, by 'name removed'. Hosted CGI, with NO adverts
    and FREE. http://www.name removed.com -!>
    <form method=POST name="contact" onSubmit="retur n validate()"
    action="http://www.name removed.com/cgi-bin/formprocessing/forms.pl">
    <input type="hidden" name="username" value="my_user_ name">
    <input type=hidden name="activenum ber" value="88888888 8">


    <table>
    <tr>
    <td>
    <table>
    <tr>
    <td>Email <span class="rederror "></span></td>
    <td> <input type="text" name="Email" value="" size="40">
    </td>
    </tr>

    <tr>
    <td>Email2 <span class="rederror "></span></td>
    <td> <input type="text" name="Email2" value="" size="40">
    </td>
    </tr>

    <tr>
    <input type="submit" name="Submit" value="Send Contact
    Request" class='buttonSm all'></td>
    </tr>

    </table>
    </form>

    <script language="JavaS cript">
    <!-- Begin
    function validate(){

    if (document.conta ct.Email.value= ="") {
    alert("Oops! Please enter your EMAIL ADDRESS.")
    return false
    }

    return true
    }
    // End -->

    </script>
    </body>
    </html>


  • Michael Winter

    #2
    Re: comparing two text boxes

    sorry@nogo.com wrote:

    [snip]

    You have a closing BODY tag, but not an opening one. You also don't
    specify a DOCTYPE.
    [color=blue]
    > <! Form Processing, by 'name removed'. Hosted CGI, with NO adverts
    > and FREE. http://www.name removed.com -!>[/color]

    That comment isn't really a comment at all. Correct it to

    <!-- ... -->
    [color=blue]
    > <form method=POST name="contact" onSubmit="retur n validate()"[/color]

    When validating form submission, it's best to pass a reference to the
    function using the this operator. This makes naming forms unnecessary
    and makes referring to the form simpler over all:

    <form action="..." method="post" onsubmit="retur n validate(this); ">
    [color=blue]
    > action="http://www.name removed.com/cgi-bin/formprocessing/forms.pl">
    > <input type="hidden" name="username" value="my_user_ name">
    > <input type=hidden name="activenum ber" value="88888888 8">
    >
    >
    > <table>
    > <tr>
    > <td>
    > <table>[/color]

    You've nested a table. Not only is it unnecessary, but you've done it
    incorrectly as there's no evidence of you ending the innermost table.
    I seriously suggest you validate (<URL:http://validator.w3.or g/>) your
    mark-up to catch mistakes like these.

    [snip]
    [color=blue]
    > <tr>
    > <input type="submit" name="Submit" value="Send Contact
    > Request" class='buttonSm all'></td>[/color]

    You've missed the opening TD tag.

    [snip]
    [color=blue]
    > <script language="JavaS cript">[/color]

    The language attribute has been deprecated for over six years.
    Instead, use the (required) type attribute:

    <script type="text/javascript">
    [color=blue]
    > <!-- Begin[/color]

    Hiding script and style content with SGML comments is equally
    out-dated. Don't bother any more.
    [color=blue]
    > function validate(){[/color]

    To take advantage of the changes in the call I proposed earlier, you
    need to alter the function declaration:

    function validate(form) {
    [color=blue]
    > if (document.conta ct.Email.value= ="") {[/color]

    You can now reduce

    document.contac t...

    to

    form...

    To confirm the e-mail address, just compare the value properties of
    both INPUT elements:

    function validate(form) {
    var elem = form.elements;

    if(!/.+@.+\..+/.test(elem['Email'].value)) {
    alert('Please enter a valid e-mail address.');
    return false;
    }
    if(elem['Email'].value != elem['Email2'].value) {
    alert('The two e-mail addresses do not match.'
    + ' Please check for errors.');
    return false;
    }
    return true;
    }

    [snip]

    Hope that helps,
    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    Working...