View Full Version : how to force fire the onChange event

09-05-2006, 08:56 AM
I have an item whose value is set by javascript code.
I want to place an onChange event handler on this item, only problem is that the onChange event handler will not fire if the items value is changed by javascript code.

Is there anyway of forcing the onChange event to fire??

09-05-2006, 10:39 AM
Yes, when you change the element's value using javascript add a line:


where elID is the element's id.

09-05-2006, 11:06 AM
throws up the following error:
object doesn't support this property or method

09-05-2006, 01:52 PM
got it to work....
I was trying to fire the event on a hidden item (which doesn't work) have changed it to a visible item and it now works.

Thanks for the help...

09-05-2006, 09:45 PM
If you want to run the event on an invisible element, depending upon the event, you may be able to do so by running the event's code rather than the event itself. Say the onchange event was:

onchange="alert (this.value);"

In your script that alters that element use this line:


03-15-2009, 10:54 PM
Yay for old topics! This just totally helped me.

And firing the event for a hidden <select> element works just fine for me in IE6+.