Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

getElementById click in firefox not working

Posted on 2007-04-08
14
Medium Priority
?
2,055 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 53

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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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 53

Accepted Solution

by:
Ryan Chong earned 300 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
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)

715 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