I have one input and one button. When I erase the input and the input has changed, the price () function should be called. Also, when I click the button, the price () function is called.
The problem is that when the user changes the input value and presses the button, the price () function is called twice. I do not want this to happen.
I tried the old-fashioned way by setting the variable "inPriceFunction" to true when entering and checking to see if it was set before entering. This did not work, because two events (blur and click) are executed at the same time, there was no time for the if and variable parameters.
How can i avoid this?
What I tried:
<div> <input type=text onchange="price();" /> </div> <button onclick="price();" />test</button> <script> called = 0; function price() { if(called == true){ return; } else { called = true; } console.log("called"); called=false; } </script>
source share