开发者

java script is not working in mozila

开发者 https://www.devze.com 2022-12-31 00:44 出处:网络
I have added some javascript in html page for input validation.same page is working correct in IE and chrome but in mozila its not working.The problem is when user inputs invalid data its supposed to

I have added some javascript in html page for input validation.same page is working correct in IE and chrome but in mozila its not working.The problem is when user inputs invalid data its supposed to show alert msg box and when user clicks OK it should return false to form...BUT mozila is not waiting for alert box it just shows alert box for 5-6 sec and then goes to next page defined in form action="nextpage.php"

 function validate_form(thisform) 
    {
    with (thisform) 
        {
        if (validate_required(oldpassword, "<b>Error: </b>Please enter the Old Password!") == false)
        { changeColor("oldpassword"); return false; }

        else if (valid_length(newpassword, "<b>Error: </b>Please enter the New Password!!") == false)
        {newpassword.value=""; changeColor("newpassword"); return false; }

        else if (valid_length(cnfpassword, "<b>E开发者_Go百科rror: </b>Please enter the Confirm Password!!") == false)
        {cnfpassword.value=""; changeColor("cnfpassword"); return false; }

        else if (document.getElementById('newpassword').value != document.getElementById('cnfpassword').value)
        {changeColor("newpassword");cool.error("<b>Error: </b>Passwords entered are not same!"); 
        newpassword.value="";cnfpassword.value="";return false;}

    }
}function validate_required(field, alerttxt) 
    {
    with (field) 
        {
        if (value == null || value == "") 
            {
           cool.error(alerttxt);return false;
            }
        else 
            {
            return true;
            }
        }
    }

cool.error is nothing but CSS nd Js for alert box.I thing there is not any problem in my code weather problem is in some browser settings.Is it so??? because it is working fine in IE and Chrome.


You're using a non-standard IE-only behavior that creates global variables for every element with an ID.

To fix it, add a global variable for each element that you use:

var oldpassword = document.getElementById("oldpassword");

Also, you should never use Javascript's with block.
It is very different from VB's with block, and should not be used unless you truly understand its pitfalls and shortcomings. It will also slow down your code.


You could also use some javascript library to get past browser issues. I'm rooting for jQuery.

0

精彩评论

暂无评论...
验证码 换一张
取 消