IE7 ignores my javascript validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mustapha ZEGAOU
    New Member
    • May 2011
    • 1

    IE7 ignores my javascript validation

    Hi

    I'm struggling finding a reason why this is happening in IE7...

    I have a simple form such as:

    Code:
    <html> 
    <head> 
    <script type="text/javascript"> 
    function validate_required(field,alerttxt) { 
        with (field)   {   
            if (value==null||value=="")     {     
                alert(alerttxt);
                return false;     
                }   
            else {     
                return true;     
                }   
            } 
        } 
        
    function validate_form(thisform) { 
        with (thisform)   {   
            if (validate_required(email,"Email must be filled out!")==false)   { 
                email.focus();
                return false;
                }   
            } 
    } 
    </script> 
    </head>  
    <body> 
    <form action="submit.htm" onsubmit="return validate_form(this)" method="post"> 
    Email: <input type="text" name="email" size="30"> <input type="submit" value="Submit"> 
    </form> 
    </body>  
    </html>
    When not entering anything in the email field the javascript detects it and the alert message is displayed BUT as soon as you click OK the form is submitted/processed to the action page "submit.htm ".

    Does anyone know why this is happening under IE7 it does work fine with Firefox though...?

    The same happens for many of my forms.

    Thanks for any input, I'm really struggling at the moment
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    I'm not sure if this will make a difference (I haven't tested), but try removing the use of "with" and access the fields directly.

    Comment

    Working...