Javascript Validation On Multiple Select Lists

I do not the Others option in your selection options list and there is no other text box.

I hope following should help you if you have an option Others in your selection box and text box next to it:


var minNum = 1; 
var maxNum = 3;
var isOthers = false;
function checkListBoxSize(){
	var oSelect = document.getElementById("category_id");
	var count = 0;
	for(var i = 0; i < oSelect.options.length; i++){
		if(oSelect.options[i].selected){
			count++;
			if(oSelect.options[i].value == 'Others'){
				isOthers = true;
			}
		}
		if(count > maxNum){
			alert("Can't select more than 3");
			return false;
		}
	}
	if(count < 1){
		alert("Must select at least one item");
		return false;
	}
	if(isOthers == true && document.getElementById('other_textbox').value == ''){
		alert('You have selected others option but did not enter anything in the text box.');
		return false;
	}
	return true;
}