jqueryonclickhtml-selectjquery-chosen

jquery chosen: how to onClick for a special option


I'm using jquery chosen to create a multiple select box. My problem is, that the third option must to open a new window and must not select. (later the user can create a new option in this window)

can someone help me to realize this? My idea is to use $('.chosen-select').on('change'...) for this and remove the selected item from the list. But I don't know how

<div class="wrapper">
  <select data-placeholder="options" style="width:350px;" multiple class="chosen-select">
     <option value=""></option>
     <option value="1">1</option>
     <option value="2">2</option>
     <option value="3" onClick="openPopup()">3</option>
 </select>
</div>

thank you!


Solution

  • I've solved it:

     $('.chosen-select').chosen().change( function() {
          var selectedValue = $(this).find('option:selected').val();
          if(selectedValue=='3'){
            $(this).find('option:selected').prop("selected",false);
            openPopup();
          }
          $('.chosen-select').trigger("chosen:updated");
        });