Skip to content
Advertisement

Preventing a running event from execution in javascript/jQuery

I am having a drop down as follows.

JavaScript

I am having a change event handler which gets invoked when user selects Two, which is as follows .

JavaScript

Also, I am having another click event handler which gets invoked when user clicks on Try Manually, which is as follows.

JavaScript

So, when user selects Two ,then a message – ‘Processing…TryManually’ gets displayed and then after successful ajax call a drop down gets displayed.

If ajax call took long time then message stays on screen. During this time if user clicks on Try Manually, then before displaying text box I should cancel the running ‘change’ event handler.

How to achieve this ?

Advertisement

Answer

You could have a global variable, so that you can cancel the event if it is onscreen, like this:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement