Skyrim
Skyrim

Reputation: 162

Getting ‘Stop running this script’ message in IE7

I need to execute the below code on checkbox click

            for (i = 0; i < dropDownCtrl.length; i++) {

                $("#dropDownCtrl option[value='" + dropDownCtrl[i].objName + "']").remove();
           }

However am getting ‘Stop running this script’ message in IE7, due to large dropDownCtrl.length value.

Can anyone help me out how to integrate my code in the code mentioned in the URL given below,

http://www.picnet.com.au/blogs/Guido/post/2010/03/04/How-to-prevent-Stop-running-this-script-message-in-browsers

Please help.

Upvotes: 1

Views: 198

Answers (2)

Praveena M
Praveena M

Reputation: 522

Since you are using jQueryUI Multi Select control and CheckAll is causing the issue. I have tried replacing .each() with the for loop in the _toggleChecked event which was causing timeout. After the change its working fine without any script errors.

this.element
    .find('option')
    .each(function() {
     //if(!this.disabled && $.inArray(this.value, values) > -1) {
        self._toggleState('selected', flag).call(this);
      //}
    });

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

Step one: Don't use jQuery.

var opts = document.getElementById('dropDownCtrl').options, lookup = {},
    l = dropDownCtrl.length, i;
// first use "lookup" as a quick lookup table - otherwise we'd have O(n*m) !
for( i=0; i<l; i++) lookup[dropDownCtrl[i].objName] = true;
// now we can do this in O(n+m), much better.
l = opts.length;
for( i=0; i<l; i++) {
    if( lookup[opts[i].value]) opts.parentNode.removeChild(opts[i]);
}

Ta-da! Should be much, much faster now.

Upvotes: 3

Related Questions