Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form validation works in IE, not in Firefox

    Hi,

    I am validating form input to see if there are any blanks, and it works fine in IE, but not in Firefox. In Firefox, it gives the error "Fill in First Name", but then goes ahead to show the "Thank You" page. It should actually focus on the field and stay there.

    Here's my code. You can see it in IE or firefox at http://www.brandrich.com/formval.html


    I have posted it below also. Any help is appreciated to find the fix for Firefox.

    Thanks a lot.

    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function validate(frm) {
    //
    // Customised Form Validation script - Vinai Prakash, Brandrich.com
    //
    // if (frm.givenname.value.length == 0)
    if (document.forms[0].elements[0].value.length == 0)
    {
    alert("Please enter your First Name.");
    frm.document.forms[0].elements[0].focus();
    return false;
    }
    else if (document.forms[0].elements[1].value.length == 0)
    {
    alert("Please enter your Last Name.");
    frm.document.forms[0].elements[1].focus();
    return false;
    }
    else if (document.forms[0].elements[2].value.length == 0)
    {
    alert("Please enter the Email address.");
    frm.document.forms[0].elements[2].focus();
    return false;
    }
    //
    // Now check the Email field for the "@" symbol
    //
    else if (document.forms[0].elements[2].value.indexOf("@") == -1)
    {
    alert("Please enter a valid e-mail address.");
    frm.document.forms[0].elements[2].focus();
    return false;
    }
    else {document.forms[0].elements[3].value = document.forms[0].elements[2].value;
    return true;
    };
    }
    //-->
    </script>

    </head>
    <body>

    <div id="myform" align="right">
    <h4 class="sidebar-title">Get Blog Updates by Email</h4><br>
    <form method="POST" action="http://www.brandrich.com/cgi-bin/form.pl" NAME="MyForm" onSubmit="return validate(MyForm)">
    First Name: <input type="text" id="fname" name="first name" value="" size="20"><br>
    Last Name: <input type="text" id="lname" name="last name" value="" size="20"><br>
    Email : <input type="text" name="Email" value="" size="20"><br>
    <input type="hidden" name="email">
    <input type="hidden" name="newsletter_name" value="Business Email Marketing Blog">
    <input type="hidden" name="recipient" value="subscribe@brandrich.com">
    <input type="hidden" name="Subject" value="Subscribe to Business Email Marketing Blog">
    <input type="hidden" name="redirect" value="http://www.brandrich.com/thankyou.html">
    <input type="submit" name="submit" value="Email Blog Updates">
    </form>
    </div>


    </body>
    </html>

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by vinaip View Post
    Hi,

    I am validating form input to see if there are any blanks, and it works fine in IE, but not in Firefox. In Firefox, it gives the error "Fill in First Name", but then goes ahead to show the "Thank You" page. It should actually focus on the field and stay there.
    The error is plainly indicated in the JS console. Your referencing scheme is not consistent. You're passing the name of the form to the validate function, which tries to reference it:
    Code:
    frm.document.forms[0].elements[0].focus();
    when it should be:
    Code:
    frm.document[frm].elements[0].focus();
    That said, it would be better to pass a reference to the form
    Code:
    onSubmit="return validate(this)">
    then in the function, refer to the elements: frm.elements[...]

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reaply Arty. I tried as per your suggestions, and created
    http://www.brandrich.com/formval3.html

    but now it does not work in IE or Firefox.

    My earlier version at http://www.brandrich.com/formval.html is atleast working in IE properly and partially in FF.

    Please advice if I goofed something in the formval3.html ?

  • #4
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Arty. I tried some more, and figured it out. Now it is working fine.

    Incidently, i did not know what a JS console was. So I google it and found out how to use it. Thanks a lot!

    Regards,
    Vinai
    http://www.brandrich.com


  •  

    Posting Permissions

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