Solved

getElementById click in firefox not working

Posted on 2007-04-08
14
2,040 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
14 Comments
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 18874004
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 52

Expert Comment

by:Ryan Chong
ID: 18874009
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
ID: 18874028
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Stealthrt
ID: 18874032
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
ID: 18874044
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
ID: 18874048
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
ID: 18874054
onMouseOver="var MyIframe = document.getElementById("Switch");var oDoc = (MyIframe.contentWindow || MyIframe.contentDocument);if (oDoc.document) {oDoc = oDoc.document;oDoc.getElementById('DownON').click()";}"
0
 

Author Comment

by:Stealthrt
ID: 18874058
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
ID: 18874125
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
ID: 18874135
Ok. Yes, please let me know! :o)

David
0
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 75 total points
ID: 18874139
>>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
ID: 18874148
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
ID: 18874151
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
ID: 18874173
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem in javascript 17 59
display data from multiple ajax calls 9 44
Search result not displaying in grid 7 13
Why is my select returning NaN 23 46
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

752 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