Reputation: 162
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,
Please help.
Upvotes: 1
Views: 198
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
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