First, an onchange error onchange : when an element loses focus (that is, it “blurs”), the change usually ends (usually I say because the script can change the element without user interaction).
For those elements that first require onblur , you can turn off the onchange handler and run onchange (or even a custom event) from the onblur handler. This will ensure the correct order, even if it works more. To detect a change, you can use the state variable for this field.
As a general remark, however, the need for such synchronization is a sign that the approach you use to solve any problem you solve may require more work, although sometimes it cannot be avoided. If you are sure that this is the only way, try one of these methods!
EDIT: To elaborate on the last point, you will need to follow some assumptions about your event model. Do you assume that every change event is followed by blur and it is not processed otherwise or every change processed, and those followed by blur get further processing after onblur with them? In any case, if you want to ensure the execution of the order, the processors need access to the shared resource (global variable, property, etc.). Are there other types of events that you might want to use? ( input ?). Finally, this link contains some information about the change event for Mozilla browsers: https://developer.mozilla.org/en-US/docs/Web/Reference/Events/change . The third "bullet" solves the problem of the order of events.
source share