Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Member #
    33977
    i am new to web design and have to create a username textbox (must be email), with 2 password validations textboxes. I have my function but obviously something here is wrong, because nothing at all is happening when i click submit. can someone help me ? thanks in advance for the help guys!!



    <html>
    <head>
    <script language="JavaScript" type="javascript/text">
    <!--
    function CreateAcct(element) {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    if (!emailPattern.test(element.username.value)){
    alert("Error! Please re-enter a valid address!");
    document.form1.username.focus();
    return false;
    }

    var passwordPattern = /^[a-zA-Z0=9]{8,10}$/;
    if (!passwordPatterm.test(element.password.value)){
    alert("Error! Password must be 8 to 10 characters");
    document.form1.password.focus();
    return false;
    }

    var passwordPattern = /^[a-zA-Z0=9]{8,10}$/;
    if (!passwordPatterm.test(element.confirmpassword.val ue)){
    alert("Error! Password confirmation must be 8 to 10 characters");
    document.form1.confirmpassword.focus();
    return false;
    }

    if (element.password.value!=element.confirmpassword.v alue){
    alert("Error! Please enter same passwords!");
    document.form1.password.focus();
    return false;
    } else {
    alert("Thank you for completing the form!");
    return true;}
    }

    //-->
    </script>
    </head>
    <body>
    <form name="form1" onsubmit="return CreateAcct(this)">
    Username (Required - must be a valid email address): <input type="text" name="username" value=""><br>
    Password (Required): <input type="password" name="password" value="" ><br>
    Confirm Password (Required): <input type="password" name="confirmpassword" value=""><br>
    <input type=submit value="Submit">
    </form>
    </body>
    </html>

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    if (!passwordPatterm <-- that should be an "n". Splelin conts!

    "element" needs to be defined as well. I'd just replace anywhere it says "element." with "document.form1."...that's be the easiest thing.

    The point I'm trying to make is that you have some Javascript errors. What you'll need to do is debug them. How you do that depends on your browser of choice, so if you let us know what that is, we can tell you where ou can find your errors.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Member
    Join Date
    Nov 2012
    Location
    Tampa. FL
    Posts
    59
    Member #
    33844
    Liked
    21 times
    It looks like "element" is defined in the onsubmit attribute of the form by passing "this" as an argument for the function. I agree with TheGAME1264 in that it's not really best practice but it should work once you change the patterm spelling error to pattern
    TheGAME1264 likes this.
    Freelance Web Developer

  5. #4
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Member #
    33977
    fixed my errors, and everything is working like it should! thanks so much guys!!!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:50 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com