Hi 1DMF, thank you for your response. Theoretically I know that I need to check the number of indexes Practically I don't know how to do that. Could you please give me an example?
If the element is like this.
[tt]
<select name="x" multiple="multiple" size="11" onblur="countit(this)">
<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="f">f</option>
<option value="g">g</option>
<option value="h">h</option>
<option value="i">i</option>
<option value="j">j</option>
<option value="k">k</option>
</select>
[/tt]
The handler countit() shows you how to obtain the counts of options selected.
[tt]
function countit(obj) {
var n=0;
for (var i=0;i<obj.options.length;i++) {
if (obj.options.selected) n++;
}
alert("# of options you've selected: " + n};
if (n>=8) {
alert("warning: # of options selected shouldn't be more than 8.")
}
}
[/tt]
You can do things based on the count in the onsubmit validation or elsewhere. The algorithm is still the same. The rest is your call.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.