• Hello
    I’m getting crazy with this.
    Seems so strange that all the newsletters plugins (payed plugins) not have this feature.
    I just want to add in a newsletter subscription form a secondo “email” field and insert a Javascript that tells shows an error if the user write different emails.

    Seems so simple but… seems impossible.

    I found this JS to add in the page directly

    <script type="text/javascript" language="JavaScript">
    <!--
    //--------------------------------
    // This code compares two fields in a form and submit it
    // if they're the same, or not if they're different.
    //--------------------------------
    function checkEmail(theForm) {
        if (theForm.EMAIL_1.value != theForm.EMAIL_2.value)
        {
            alert('Those emails don\'t match!');
            return false;
        } else {
            return true;
        }
    }
    //-->
    </script> 
    
    <form action="../" onsubmit="return checkEmail(this);">
    <p> Enter Your Email Address:<br>
    <input type="TEXT" name="EMAIL_1" size="20" maxlength="20">
    <br>
    Please Confirm Your Email Address:
    <br>
    <input type="TEXT" name="EMAIL_2" size="20" maxlength="20">
    <br>
    <input type="SUBMIT" value="Send Address!"></p>
    </form>

    or this one

    <html>
    <head>
    <script type="text/javascript">
    function chkstr()
    {
    var Eml1=document.getElementById("eml1").value;
    var Eml2=document.getElementById("eml2").value;
    
    if(Eml1 != Eml2) {
    	alert("Email addresses don't match.");
    	return false;
    	}
    }
    </script>
    </head>
    <body>
    <h1>js-strcmp.html</h1>
    <form action="#" method="get" onsubmit="return chkstr();">
    <input type="text" name="eml1" id="eml1" value="Email 1" /><br />
    <input type="text" name="eml2" id="eml2" value="Email 2" /><br />
    <input type="submit" value="Submit" />
    </form>

    Problem is that if I publish a page with this text, it not works.
    The form appears, I click on submit but the page just reloads without no errors.

    Any help appreciated.

    Thanks!

Viewing 1 replies (of 1 total)
  • A number of forms plugins will handle this nicely. I personally like Gravity Forms, but most of them will give you an option to verify the email like you’re trying to do. It’s certainly easier than fighting with code.

    They also will easily tie into mailing list services (MailChimp, Constant Contact, etc), so I would look into it.

Viewing 1 replies (of 1 total)

The topic ‘Two email fields match-validation (Javascript)’ is closed to new replies.