On my aspx page, there is a listbox (techGroups) with preselected items that users can change. I also have a reset button that should restore the listbox to its original selections when clicked. However, I am encountering an issue where only the first preselected item remains selected after clicking the reset button.
I created the following JavaScript function for the onclientclick event of the reset button. It retrieves the preselected items from a hidden field and attempts to reselect them in the listbox:
function reset() {
var selectedGroups = hiddenfield1.value.split(","); // The preselected items are saved in a hidden field.
for (var i = 0; i < techGroups.options.length; i++) {
for (var j = 0; j < selectedGroups.length; j++) {
if (techGroups.options[i].value == selectedGroups[j]) {
techGroups.options[i].selected = true;
}
}
}
}
If anyone could review my code and point out what might be incorrect, I would greatly appreciate it. Thank you.