Manually changing a value does not raise a Change event if the value has been changed before the program

We have an input type = "number", and we set the method onChange.

The default value for input is 0.

Then we change the value programmatically to say: 10.

Now we again change the value to 0.

The method is onChangenot called when manually applied. I think that since the event was not triggered when we programmatically changed our value to 10. Thus, the control considers that the value is still 0.

This only happens when I manually set the value to the value that it had before the program change. If I use any other value to make changes manually, the event onChangefires correctly.

+5
source share
2 answers

Programmatically changing a form control value does not cause its change handler, possibly because the change event was indicated as taking place after the user changed the value and the control lost focus. Software changes did not correspond to this sequence (software setting focus and blur to imitate user actions did not help, although an event with a program change could be sent to an element).

HTML5 introduces a new input event that fires whenever an input accepts user input:

<input id="i0" oninput="alert(this.value);" value="">

onchange, , .

, HTML5 (, , , ), , .

+4

onchange. , onchange. .

0

All Articles