- What triggers the ChangeEvent when it is fired? / How does it function "internally"?
The change Event (not to be confused with an actual ChangeEvent interface) does not actively monitor anything. Events, including the change event, are triggered by specific algorithms within the system.
For example, in the case of an input element with a "text" type, the algorithm responsible for firing the change event can be found here.
You can find more information on different input types and their respective activation behaviors here.
- Is it possible to detect changes triggered by JavaScript without using intervals?
Absolutely! If your JavaScript code is responsible for making these changes, you can set up a callback function to handle them accordingly.
For debugging purposes, you can override the value property of your input element to trigger your callback whenever the value is changed programmatically:
(JavaScript example code provided)
However, relying on such hacks may indicate underlying design issues that should be addressed.
- I noticed that the ChangeEvent does not occur naturally when values are updated via code as no Event object is created. What is the rationale behind this design decision?
The decision was made because both the change and input events are meant to signify user interaction with the control element. It is expected that as a developer, you have full control over the scripts running on your page, so events like these should be triggered intentionally by your scripts rather than automatically for actions performed by your code.