Controlling select change function on Unselect event

1.9k views Asked by At

In my Java Script, I am using a select tag to select multiple values one after the other,

My requirement is passing this newly selected value to a function.

Everything works perfect with jQuery on Change function, but when I deselect the item from the list still it taking the item and passing it to function.

How can I clear this problem?

 $("#clients").off('change').on('change', function(){
 selectedclientname = $(this).closest('select').find('option').filter(':selected:last').text();
 selectedclientid = $(this).closest('select').find('option').filter(':selected:last').val();
  function1(selectedclientid);
 });

enter image description here

1

There are 1 answers

0
Gopikrishn On

Finally I figure it out by the following way

   $("#clients").off('change').on('change', function(evt, params){              
         var itemSelected = false;
         console.log("::::::::::::::deselected"+ params.deselected);
         console.log("::::::::::::::selected"+ params.selected);
         if(params.selected != null)
             {
               itemSelected  = true;
             }
         else{
             itemSelected  = false;
             }
      });