hai,
How can i restrict number of selections in listbox using javascript.
ie. only 3 items are allowed to select , also atleast one item should select.
thanks in advance
-
var selectedOptions = new Array(); //array containing the ids of selected options
-
function doSelect(whom) {
-
var temp;
-
if (selectedOptions.length == 3) { //required length
-
temp = selectedOptions.shift();
-
document.getElementById(temp).selected = false;
-
}
-
temp = selectedOptions.push(whom.id);
-
}
-
On the
onclick of every option, call the function
doSelect(this).
* And don't forget to set autocomplete=off to the select input.
Check if this works or not. I didn't check it.
PS: Are you sure there's not any HTML attribute to restrict it?