SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2003
    Location
    kerry
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript func verify() not working correctly

    Anyone know whats wrong with the following javascript. Verify() should
    check the other two functions and only submit the form if both return true however the form submits no matter what is entered in the "confirmnum" textbox (should only be digits)
    HELP!!


    <%@Language ="VBScript"%>
    <%option explicit%>

    <!-- #include file = "header.html" -->
    <html>
    <head>
    <title>Cancel Details Page</title>
    <link rel=stylesheet type=text/css href="style.css">
    <style>
    img{border-style:none}
    td{padding-right:5}
    td{padding-left:15}
    table{align:center}
    </style>

    <script language="javascript">
    function isEmail(str) {
    // are regular expressions supported?
    var supported = 0;
    if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
    }
    if (!supported)
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    return (!r1.test(str) && r2.test(str));
    }

    function validateOrderNumber(confirmnum)
    {
    var GoodChars = "0123456789 "
    var i = 0

    //check if empty, do a trim to ensure string of spaces will fail
    if (rightTrim(confirmnum)=="") {
    alert("Please specify a phone number.");
    return 0;
    }
    //check if valid
    for (i =0; i <= confirmnum.length -1; i++)
    {
    if (GoodChars.indexOf(confirmnum.charAt(i)) == -1) {
    alert("the order confirmation number you provided contains an illegal character: " + confirmnum.charAt(i));
    return 0;
    }
    }
    return 1;
    }
    function Verify()
    {
    var errorFields='';
    var errorMessage='';
    var email=canceldetails.email.value;
    var confirmnum=canceldetails.confirmnum.value;

    //canceldetails.submitButton.disabled = true;
    //Check for corectness of the input
    // if(!validateOrderNumber(confirmnum)) {
    // canceldetails.confirmnum.focus();
    // event.returnValue=false;
    // }


    if (!isEmail(email)) {
    event.returnValue=false;
    errorFields+=' .Email Address\n';
    }


    //Build error message and display it.
    if (errorFields!='') {
    errorMessage+=' The following fields are incorrect:\n';
    errorMessage+=errorFields;
    alert(errorMessage);
    canceldetails.submitButton.disabled = false;
    }

    }

    </script>

    </head>
    <body>
    <form name="canceldetails" method="POST" action="cancelConfirm.asp" onSubmit ="Verify(); return true">
    <h3>Please provide us with these order details</h3>
    <p>Email Address:
    <input type=textbox name ="email" maxlength="50">
    </p>
    <p>Order Confirm No.
    <input type=textbox name ="confirmnum" length="50">
    </p>
    <br>
    <p>
    <input type="submit" name="submitButton" value="Cancel my booking now!">
    </p>

    </form>
    </body>
    </html>

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Fort Lauderdale
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where you have:
    onSubmit="Verify(); return true;"

    you want:
    onSubmit="return Verify();"

    What you have always returns true. You want it to return whatever Verify() returns.

    www.unpossiblemedia.com - A Fort Lauderdale based multimedia company.

  3. #3
    SitePoint Member
    Join Date
    Feb 2003
    Location
    kerry
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried this and it catches an invalid email address error but allows any input in the confirmnum field, leading to a database error. Any other ideas?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •