# Javascript Validation On Multiple Select Lists



## calthephenom (May 2, 2009)

i couldn't find any errors
try testing it out on www.htmledit.squarefree.com


----------



## calthephenom (May 2, 2009)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
var minNum=1; var maxNum=3;
function checkListBoxSize(){
oSelect=document.getElementById("category_id");
var count=0;
for(var i=0;i<oSelect.options.length;i++){
if(oSelect.options_.selected)
count++;
if(count>maxNum){
alert("Can't select more than 3");
return false;
}
}
if(count<1){
alert("Must select at least one item");
return false;
}
return true;
}

</script>
</head>

<body>
<form onsubmit="return checkListBoxSize()">
<select multiple="multiple" id="category_id" name="category_id" size="10" onchange="return false;">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
<option value="e">e</option>
<option value="Other">Other</option> 
</select>
<input name="" type="submit"/>
</form>
</body>
</html>

i got that for you_


----------



## calthephenom (May 2, 2009)

what is it you are trying to make?


----------



## elf (Jul 19, 2002)

It appears the OP was a bot of some sort, it has been dealt with. Thank you for trying to help though.


----------

