Don't fire onchange event if its called from a specific function?

279 Views Asked by At

I have a drop-down which is associated with onchange event.

<select id="code" class="form-control">
  <option value="0"> Select Code </option>
  <option value="1"> 3456741 </option>
  <option value="2"> 1741100 </option>
</select>

I am using select2 customization:

$("#code").select2();

My onchange event:

$("#code").change(function(){
    getDetails($(this).val());
}

I have a button with click event:

$(".btnCancel").on("click", function (e) 
{
   $("#code").val(parseInt(myValue)).trigger("change");
}

When I click cancel button, it calls onchange event. I want to prevent change event, however I want drop-down to show the value which I am selecting for this function but do not call change event which is associated with this drop-down. I already tried following:

e.preventDefault();
e.stopPropagation();
0

There are 0 best solutions below