Re: onChage event



"Ayush" <"ayushmaan.j[aatt]gmail.com"> wrote in message
news:OoKNRe15HHA.3740@xxxxxxxxxxxxxxxxxxxxxxx
[Markgoldin] wrote-:
I am sripting a page that has a dropdown list. While I can set its value
I can't fire its onChange event witch runs a function.


Can I run this function programmatically or how can I trigger the
onChange event from the script?

if(selectElement.onchange)
selectElement.onchange()


That will probably work in most of the common scenarios. However if an
event handler has been added with attachEvent or addEventListener those
handlers won't run by calling onchange.

In IE you can simply use selectElement.fireEvent('onchange').

In Mozilla it is a little trickier. The following will work for Firefox:-

var ev = document.createEvent("Event")
ev.initEvent("change", true, false); // can bubble, can't cancel.
selectElement.dispatchEvent(ev)


--
Anthony Jones - MVP ASP/ASP.NET


.



Relevant Pages

  • Re: binding an event to a variable.
    ... have tried binding the onchange event to it, ... Thanks for that ASM. ... event handler to the variable. ...
    (comp.lang.javascript)
  • Re: Stack Overflow !
    ... In article, "Bruce Roberts" ... >Text property of a control within the control's onChange event. ... Recursion caused by changes to the object within its change event handler may ...
    (comp.lang.pascal.delphi.misc)
  • Re: javascript newbie needs help with function
    ... I have two pulldowns on this page, each has an onChange event. ... I I use your script it only ...
    (microsoft.public.scripting.jscript)
  • Re: Onchange Event
    ... I need some help with an onchange event for one of my select boxes on my form. ... Don't post ASP code. ... Post the HTML and script that it generates. ... Don't name a function "reload". ...
    (comp.lang.javascript)
  • Re: Not allow submit if data changed
    ... value changed (by attaching script to the onchange event of each control). ...
    (microsoft.public.dotnet.framework.aspnet)

Loading