Solved

getElementById click in firefox not working

Posted on 2007-04-08
14
2,019 Views
Last Modified: 2013-11-18
I need to see why the getElementById().click() doesnt work in Firefox? It works ok in IE6 but not FF. I've herd that the click() event is not supported by FF. Is there any way to fix it?

Here is my code:
onMouseOver="parent.Switch.document.getElementById('DownON').click()"

There is an iframe on the page called "Switch". inside that it loads a html file with a 2 buttons with an id of "DownON" and "DownOFF". Once that button is clicked it moves some text down. Works fine like i said in IE but not FF.

The JavaScript console in Firefox tells me after rolling over the image with my mouse:
"parent.Switch has no properties"

The iframe code is this:
<iframe id="Switch" src="MiddlePage.html" width=615 height=337 marginwidth=0 marginheight=0 frameborder=0 scrolling=no></iframe>

The MiddlePage buttion code is this:
<input type="button" id="downON" name="downON" onclick="scroll(-4)" /><input type="button" id="DownOFF" name="DownOFF" onclick="noScroll()" />

David
0
Comment
Question by:Stealthrt
  • 6
  • 6
  • 2
14 Comments
 
LVL 21

Expert Comment

by:Dale Burrell
Comment Utility
Unless I am mistaken all your code is within the IFRAME - therefore you shouldn't need to reference the parent?

onMouseOver="document.getElementById('DownON').click();"
should work quite happily I would have thought?
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
try like:

onMouseOver="window.parent.frames[0].document.getElementById('downON').click()"


also, Javascript is case-sensitive, it should be as "downON", NOT "DownON"..
0
 

Author Comment

by:Stealthrt
Comment Utility
Thanks for the fast replys guys.

I have tryed the changing the code to:
document.getElementById('DownON').click();

But it still does nothing. Gives me the error:
document.getElementById("DownON") has no properties

Ryancys: Thats the ID's name just as it appears on the button itself. Like i said, it works fine in IE so the code works, it just seems to have trouble in FF.
0
 

Author Comment

by:Stealthrt
Comment Utility
And to correct something that dale_burrell said:
The onMouseOver="parent.Switch.document.getElementById('DownON').click()" is OUTSIDE of the iframe. It controls the 2 buttions within the iframe.

David
0
 
LVL 21

Expert Comment

by:Dale Burrell
Comment Utility
I wouldn't assume anything from the fact that it works in IE :)

The document is accessed different in IE & Firefox... here is some code that should work in both:

var MyIframe = document.getElementById("Switch");
var oDoc = (MyIframe.contentWindow || MyIframe.contentDocument); // Handle IE & Firefox
if (oDoc.document)
{
    oDoc = oDoc.document; // oDoc is now IFRAME Document
    oDoc.getElementById('DownON').click()";
}

HTH
0
 

Author Comment

by:Stealthrt
Comment Utility
Thanks Dale: One quesiton, how would i set that code off that u posted useing the:
onMouseOver="" command?

David
0
 
LVL 21

Expert Comment

by:Dale Burrell
Comment Utility
onMouseOver="var MyIframe = document.getElementById("Switch");var oDoc = (MyIframe.contentWindow || MyIframe.contentDocument);if (oDoc.document) {oDoc = oDoc.document;oDoc.getElementById('DownON').click()";}"
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Stealthrt
Comment Utility
Ok this is how i set it up:

<script type="text/JavaScript">
function clickButtion(){
var MyIframe = document.getElementById("Switch");
var oDoc = (MyIframe.contentWindow || MyIframe.contentDocument); // Handle IE & Firefox
if (oDoc.document)
{
    oDoc = oDoc.document; // oDoc is now IFRAME Document
    oDoc.getElementById('DownON').click();
}
}
</script>

Two problems:
1) Still does not work :o(     ERROR: oDoc.getElecmentById("DownON") has no properties.
2) I need the "DownOFF" as well when the onMouseOut. Im sure i could make another function but it would be nice to have it in one thing.
0
 
LVL 21

Expert Comment

by:Dale Burrell
Comment Utility
What a coincidence but I've just run into the same problem in some code I'm writing - it seems that Firefox doesn't realide the object in question supports the click() function... working on it - will let you know if I solve it.
0
 

Author Comment

by:Stealthrt
Comment Utility
Ok. Yes, please let me know! :o)

David
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 75 total points
Comment Utility
>>Thats the ID's name just as it appears on the button itself. Like i said, it works fine in IE so the code works, it just seems to have trouble in FF.

That's why i mentioned Javascript is case-sensitive... In IE there is less restriction on what you coding in javascript, that's why it's still working...

I tested the line:

onMouseOver="window.parent.frames[0].document.getElementById('downON').click()"

and it works in FF (2.0) before I posted here.
0
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 50 total points
Comment Utility
Actually what you've done should work - are you sure you've got the case correct? Try oDoc.getElementById('downON').click(); just to check? If that still doesn't work try this instead of oDoc.getElementById('DownON').click(); have alert(oDoc.getElementById('DownON').tagName);
0
 
LVL 21

Expert Comment

by:Dale Burrell
Comment Utility
Yes - I think ryancys is correct - my problem is that I am trying to click a link (<a>) and it doesn't seem possible in Forefox!
0
 

Author Comment

by:Stealthrt
Comment Utility
Well well... the best thing that i love about programming comes out everytime... case sensitive.

Thanks ryancys, looks like you were correct.

David
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now