Link to home
Start Free TrialLog in
Avatar of dartagnon
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?
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want to SHOW the options but still only have one selection, just change the size

<select size="4">
<option value="">Please select</option>
 <option value="1">One</option>
 <option value="2">Two</option>
 <option value="3">Three</option>
</select>
 
Avatar of dartagnon
dartagnon

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.Fields.Item("categoryID").Value)%>" ><%=(categories.Fields.Item("categoryname").Value)%></option>
                            <%
  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=false;
     }
    }
  }
}
 
</script>