views:

712

answers:

3

I wrote a page by javascript that has over 1000 lines of code and so the page is so heavy. when i run the page on the firefox, it tell me that:

A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.

Script: http://localhost:5070/resources/ir.pnusn.branch.ui.pages.BranchMap/scripts/MapAddress.js:151

and I have in MyAddress.js:151:

function fillAddress(number)
{
150:    var filedNum=0;
151:    while(document.getElementById("choice4")!=null)
        document.getElementById("choice4").click();
    nextId=1;
    for(i=0;;i++)
    {
        var cookieChoiceName=number+"-"+filedNum+"-0";
        var cookieChoiceValue=getCookie(cookieChoiceName);
        if(cookieChoiceValue==null)
        {
            //alert(document.getElementById("choice4"));
            break;
        }
        var cookieFieldName=number+"-"+filedNum+"-1";
        var cookieFieldValue=getCookie(cookieFieldName);
        if(cookieFieldValue==null)
        {
            alert(document.getElementById("choice4"));
            break;
        }
        if(cookieChoiceValue!= "-1" && cookieChoiceValue!="-2" && document.getElementById("choice"+cookieChoiceValue)!=null)
        {
            document.getElementById("choice"+cookieChoiceValue).click();
        }
        var value=utf8_decode(unescape(cookieFieldValue));
        var finalval=replacePluse(value);
        // var Resvalue=value.substr(1,value.length-1);
        document.getElementById("txt"+(filedNum-1)).value=finalval;
        filedNum++;
    }
}

and when I press continue in warning window the code work correctly. but when i increase dom.max_script_run_time in firefox configuration file it does not change and after that when I press continue again it works. What's the problem?If you want more information about the code tell me to put for you here.

+1  A: 

From your code it looks like the onclick function for 'choice4' is supposed to remove the element but isn't doing.

I'd check for a bug in that onclick.

Greg
I did't understand what you mean.Can you explain more.
JGC
+2  A: 

Your while probably is an infinite loop. The condition you are using will always be true as long as you have element with id #choise4 present. Since you are not removing this element inside the loop, then it will never finish.

RaYell
when i click on choice4 it removes some items and remove itself and create again to arrive to first condition wich i don't have choice4
JGC
If it recreates itself then next time `while` evaluates it's condition it will still be present and you will never leave this loop
RaYell
+2  A: 

This line looks suspiciously like a infinite loop to me:

while(document.getElementById("choice4")!=null)
    document.getElementById("choice4").click();
Stephen C