Solved

getElementById click in firefox not working

Posted on 2007-04-08
14
2,034 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
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 51

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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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 51

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Html form and modal / img src -problem 3 31
Make Session back to empty 9 30
function parameter and using that as array 15 23
JavaScript Loan Calculator Error 3 19
In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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 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…

820 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