dartagnon
asked on
Restrict multiple category selection
I have a multiple select option in a form, so the user can choose more than 1 category by holding down control and selecting. This means they can select any number of categories.
Is there any way to restrict this so they can only select say 1 option? Is this possible?
Is there any way to restrict this so they can only select say 1 option? Is this possible?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks x com, that worked brilliantly. Here is what I ended up with:
<select name="categoryID" size="6" multiple="true" onclick="changeOpt(this);" >
<option value="0" selected="selected">-- Select Category --</option>
<%
While (NOT categories.EOF)
%>
<option value="<%=(categories.Fiel ds.Item("c ategoryID" ).Value)%> " ><%=(categories.Fields.Ite m("categor yname").Va lue)%></op tion>
<%
categories.MoveNext()
Wend
If (categories.CursorType > 0) Then
categories.MoveFirst
Else
categories.Requery
End If
%>
</select>
<script>
function changeOpt(sel){
var opts='';
var intSel=0;
for(i=0;i<sel.length;i++){
if(sel.options[i].selected ){
intSel+=1;
if(intSel>3){
sel.options[i].selected=fa lse;
}
}
}
}
</script>
<select name="categoryID" size="6" multiple="true" onclick="changeOpt(this);"
<option value="0" selected="selected">-- Select Category --</option>
<%
While (NOT categories.EOF)
%>
<option value="<%=(categories.Fiel
<%
categories.MoveNext()
Wend
If (categories.CursorType > 0) Then
categories.MoveFirst
Else
categories.Requery
End If
%>
</select>
<script>
function changeOpt(sel){
var opts='';
var intSel=0;
for(i=0;i<sel.length;i++){
if(sel.options[i].selected
intSel+=1;
if(intSel>3){
sel.options[i].selected=fa
}
}
}
}
</script>
<select size="4">
<option value="">Please select</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>