Can you do an onchange event when the field was changed through JavaScript?

W

William Cole

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?

Thanks,

William
 
L

-Lost

William Cole said:
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?

OK, how about *adding* code to the onchange event of Field A that makes sure Field B
either has the same value, or that just simply makes Field B equal A every time A changes.

-Lost
 
R

RobG

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top