I'm trying to improve the speed of my script which is currently using
html() to replace content of a <select> element.  The
updateSelectOptions() method take an array and create a string of
options to replace the <select> element.

function updateSelectOptions(aOptions, fieldID) {
        if($("select#"+fieldID).length){
            sOptions = '';
            for (var i = 0; i < aOptions.length; i++) {
                sOptions += '<option value="' + aOptions[i].oV + '">'
+ aOptions[i].oT + '</option>';
            }
            $("select#"+fieldID).html(sOptions);
        }
    }

I've tried using replaceWith() instead of html() and that improve the
script executing from 7sec to about 1.2sec.  The only problem with
replaceWith() is that I lose the on change event that's bind to the
select element.  I've tried unbinding the before the replaceWith() and
rebinding change event after replaceWith() but the script end up
freezing when the change event is triggered for the second time.

Does anyone have a suggestion?

Reply via email to