Is there JavaScript code that I can use to select all items in a @html.listboxfor upon clicking a button?
Any examples?
I am using the following and it doesn’t work.
function listboxSelectDeselect(listID, isSelect) {
var listbox = document.getElementById(listID);
for (var count = 0; count < listbox.options.length; count++) {
listbox.options[count].selected = isSelect;
}
}
@Html.ListBoxFor(x => x.selectedUsers, Model.ListofUsers, new { style = "width:200px", size = 10, id = "lbUsers" })
Select All
Ideally, I just need to select all / unselect all items in the list. Even if it's through a checkbox.