I am using setTimeout
to overcome the slow processing script warning mentioned in " Disabling the long-running-script message in Internet Explorer ".. It is loading only the first 4 array items. How can load all the items in the dropdown using a time delay
?
Note: The browsers targeted are IE6+
Note: In my real scenario the array is retrieved from server using jQuery Ajax
References
- Uncaught ReferenceError:foobar is not defined (anonymous function)
- Arguments.callee is deprecated - what should be used instead?
Javascript
var locIterator = 0;
$(document).ready(function ()
{
function myCallback(locationArray) {
loadDropdownForLocation(locationArray);
}
function loadDropdownForLocation(locationArray) {
alert(locIterator);
if (locationArray != null && locationArray != 'undefined') {
//Loop through array
for (; locIterator < locationArray.length; locIterator++) {
var textValue = locationArray[locIterator].split('*');
alert(textValue);
//Add ddl options - text and value
var option = $('<option></option>');
option.val(textValue[0]);
option.html(textValue[0]);
$('.ddlToLocation').append(option);
// Every 3 iterations, take a break
if (locIterator > 0 && locIterator % 3 == 0) {
// Manually increment `i` because we break
locIterator++;
// Set a timer for the next iteration
window.setTimeout('myCallback(locationArray)', 100);
break;
}
}
}
}
var testArray = ["a", "b", "c", "d", "e", "f", "g", "g", "h", "i", "j"];
loadDropdownForLocation(testArray);
window['myCallback'] = myCallback;
});
HTML
<select name="ddlToLocation" id="ddlToLocation" onfocus="document.forms[0].imgArrowForToLocation.src='../Images/ArrowVisibleDB.gif';"
onblur="document.forms[0].imgArrowForToLocation.src='../Images/ArrowInvisible.gif';"
class="ddlToLocation" style="font-size: 11; width: 110px;">
</select>