Here is my issue I have two text fields (Field A, Field B). I want
Field B to be updated when Field A is changed. The problem is Field A
is being changed through JavaScript so an onChange event is not
fired. Is there any way to make this work without having to change
the code that changes Field A?
For all practical purposes, no. A couple of options are to do the
onchange action from whatever function changes Field A, or have that
function call Field A's onchange handler. Either way, you have to
modify the 'code that changes Field A'.
A clumsy alternative is to monitor the value of Field A (say using
setInterval at 100ms), and when it changes, fire the onchange
handler. But what if the value is being changed by the user and they
are only half way through changing it? You'll have to wait for the
control to change *and* lose focus. But if the user modifies it then
clicks 'submit', the monitoring function may not run between the
control losing focus and the submit event occurring, so you also need
to fire the onchange onsubmit - but (probably) not if it's already
been run. So now you need to remember if you've run the function
since the last change and blur events...
Hence it is a clumsy and impractical idea - it just keeps getting more
complex and hence less reliable.