0

I am using multiple-select.js, there when I set the value using setSelects method they are set the value and dynamically trigger the onchange function. But In my situation I want to disable this dynamically triggering. Also I can't able to modify the multiple-select.js because many one use this plugin in different module.

If I can detect is this onchange function is call from dynamically trigger or native dropdown change, my problem will solve. But don't use any global variable . Only we can use argument(may be we can use onchange="ddlchange(this)").

I am wrote a simple example like my problem

<script>
function check(ths)
{
 //Here I want to know is it come from real change or manually trigger, without using any variable
 alert("function called");
}

function trifun()
{
 //I can't modify this line, because it is in external plugin
 document.getElementById('ddl').onchange();

}

</script>
 
 <button onclick="trifun();">Trigger</button>
 
 <select id="ddl" onchange="check(this);">
  <option value="1">Test</option>
  <option value="2">Test</option>
  <option value="3">Test</option>
  <option value="4">Test</option>
  <option value="5">Test</option>
 </select>
Merbin Joe
  • 611
  • 6
  • 27

1 Answers1

0

this help you :

<html>
<head>
<title></title>
</head>
<body>
<script>
    var trg = document.getElementById("ddl");
function check(ths,event)
{
    //Here I want to know is it come from real change or manually trigger, without using any variable
       if (event.type == "change")
         alert("function called with Change");
      else
        alert("function called with click");
}

function trifun(event)
{
    //I can't modify this line, because it is in external plugin
    document.getElementById('ddl').onchange(event);


}
</script>
    <button onclick="trifun(event);">Trigger</button>
    <select id="ddl" onchange="check(this,event);">
        <option value="1">Test</option>
        <option value="2">Test</option>
        <option value="3">Test</option>
        <option value="4">Test</option>
        <option value="5">Test</option>
    </select>
</body>
</html>
Ehsan
  • 12,655
  • 3
  • 25
  • 44