Changing selectedIndex and onchange events

T

Tom Cole

Whilst I have no immediate need for it, I've noticed that if a select
element is changed via setting the selectedIndex value, it does not
fire an onchange event. Is there any reason for this? Both IE 6 and FF
2 behave the same in regards to this.

Is it the developers responsibility to fire this event in such a
situation?
 
V

VK

Whilst I have no immediate need for it, I've noticed that if a select
element is changed via setting the selectedIndex value, it does not
fire an onchange event. Is there any reason for this?

At least for IE there is:
http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onchange.asp
"The onchange event does not fire when the selected option of the
select object is changed programatically."

I don't remember if it is some standard DOM interface feature or a
"default common behavior" of all browsers. From the practical point of
view it is not so relevant though.
Both IE 6 and FF 2 behave the same in regards to this.

Yes, see above.
Is it the developers responsibility to fire this event in such a
situation?

I'm afraid so. And remember that custom events do not propagate
(bubble) so you have to fire them for each event consumer separately.
 
R

RobG

Whilst I have no immediate need for it, I've noticed that if a select
element is changed via setting the selectedIndex value, it does not
fire an onchange event. Is there any reason for this? Both IE 6 and FF
2 behave the same in regards to this.

Is it the developers responsibility to fire this event in such a
situation?

The W3C event model provides dispatchEvent, IE provides fireEvent.
The archives are a remarkable resource - Michael Winter provides a
very comprehensive answer here:

subject: How to trigger event programmatically?
<URL:
http://groups.google.com.au/group/c...k=gst&q=dispatchEvent&rnum=2#98cea9cdf065a524
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top