I have a query regarding the implementation of a script that loads country options from a predefined list. I am facing an issue where the list reloads every time the page is loaded, and when I click on a button to save the information, it resets back to the beginning of the list. Can you suggest the most suitable window method to overcome this challenge? I explored several alternative window methods but none provided a viable solution. The onloadstart method also did not yield the desired outcome.
Furthermore, my script is embedded in the User Control page, therefore I would prefer not to invoke the function from the codebehind.
window.onload = function () {
var countryElement = document.getElementById('countryId');
var listOfCountries = ["Select Country","Afghanistan", "Albania", "Algeria" ...; // (Truncated for brevity)
countryElement.options.length = 0;
for (var i = 0; i < listOfCountries.length; i++) {
countryElement.options[i] = new Option(listOfCountries[i]);
}
}