0

I want my user to select only two values in HTML dropdown. Please can anyone suggestion how I can do this. The code I am using is mentioned below.

<select style="width: 300px;height:200px;" name="graphListBox" multiple="multiple" id="graphListBox">
<c:forEach items="${graphList}" var="graphType">
    <option value="${graphType}"><c:out value="${graphType}" /></option>
</c:forEach>
</select>
  • possible duplicate of [HTML Multiselect Limit](http://stackoverflow.com/questions/4135210/html-multiselect-limit) – dsgriffin Jul 11 '13 at 09:05

2 Answers2

0

plain html does not support this. you can use javascript to catch this situation.

jquery does all the hard work for you: https://stackoverflow.com/a/4135296/2536029

Community
  • 1
  • 1
mnagel
  • 6,729
  • 4
  • 31
  • 66
0

Try

$("select").change(function () {
      if($("select option:selected").length > 2) {
          //your scenario
      }
  });
Arun Bertil
  • 4,598
  • 4
  • 33
  • 59