Scott Bennett
asked on
fireEvent('onChange') in FireFox
I have some code that programatically fires an onchange event like:
document.Myform.MyTextFiel d.fireEven t('onChang e');
works fine in IE but not in FireFox. Can anyone tell me how to make it work in FireFox?
document.Myform.MyTextFiel
works fine in IE but not in FireFox. Can anyone tell me how to make it work in FireFox?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My first thought is to use change instead of HTMLEvent. For example ...
else
{
var changeEvent = window.document.createEven t("change" );
changeEvent.initEvent("cha nge", false, true);
control.dispatchEvent(chan geEvent);
}
Let me know how that works. This might be something that browser security will prevent (IE has never been the most careful regarding that :-] ). Scripting an onchange event "firing" would be something a browser might be cautious of and prevent. If that is the case then this won't work. I am not saying we can't because I haven't read anything (yet) that said it but just a caution.
bol
else
{
var changeEvent = window.document.createEven
changeEvent.initEvent("cha
control.dispatchEvent(chan
}
Let me know how that works. This might be something that browser security will prevent (IE has never been the most careful regarding that :-] ). Scripting an onchange event "firing" would be something a browser might be cautious of and prevent. If that is the case then this won't work. I am not saying we can't because I haven't read anything (yet) that said it but just a caution.
bol
ASKER
That doesn't work either it is the first line of:
<script language="javascript" type="text/javascript" for="window" event="onload">
if (document.all) { initialize(); }
else { window.document.addEventLi stener("DO MContentLo aded", initialize, true); }
</script>
that is causing the error
<script language="javascript" type="text/javascript" for="window" event="onload">
if (document.all) { initialize(); }
else { window.document.addEventLi
</script>
that is causing the error
What are you trying to do with that script tag? The for and event "attributes" aren't part of the W3 specs to my knowledge.
Also, what is the event listener you are trying to add?
bol
Also, what is the event listener you are trying to add?
bol
ASKER
I have no Idea I just copied it from that page on the second link you posted:
http://blogs.vertigo.com/personal/aanttila/Blog/Lists/Posts/Post.aspx?ID=6
should I take that part out?
http://blogs.vertigo.com/personal/aanttila/Blog/Lists/Posts/Post.aspx?ID=6
should I take that part out?
Yes remove that for what we are working on here. That script is suggested for something else. To be honest I am not sure what or how useful it would be. It should not be required for what we are trying.
bol
bol
One thing I can tell you for sure is that script seems to be used when you want to run an "initialize" function when the page loads. We aren't worried about the page load and you probably don't even have a function with that name.
bol
bol
Thanks for coming back to close this. I'm glad that I could help. Thanks for the grade, the points and the fun question.
bol
bol
ASKER
function fireClickEvent(control)
{
if (document.all)
{
control.fireEvent("onclick
}
else
{
var clickEvent = window.document.createEven
clickEvent.initEvent("clic
control.dispatchEvent(clic
}
}
but I don't know how to convert it for use with onChange which is not a "MouseEvent"
I have done this:
<script language="javascript" type="text/javascript" for="window" event="onload">
if (document.all) { initialize(); }
else { window.document.addEventLi
</script>
<script language="JavaScript">
function fireChangeEvent(control)
{
if (document.all)
{
control.fireEvent("onchang
}
else
{
var changeEvent = window.document.createEven
changeEvent.initEvent("cha
control.dispatchEvent(chan
}
}
</script>
but it throws errors, any thoughts?