Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / February 2006



Tip: Looking for answers? Try searching our database.

"is not defined" errors only in Firefox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
forwardtrends - 28 Feb 2006 19:10 GMT
I am trying to simply make a div appear and dis-appear. The code I am
using is:

---

if(!document.getElementById) {
document.getElementById = function() {return null;};
}

function setStyle(element, property, value) {
element = document.getElementById(element);
if(element.style) {element.style[property] = value;}
}

function hideDiv() {
    setStyle(handbookPop, 'display', 'none');
}
function showDiv() {
    setStyle(handbookPop, 'display', '');
}

---

But when I use a <body onLoad="javascript:hideDiv();">

or

<a href="#" onClick="javascript:showDiv();">show div</a>

I get "handbookPop is not defined" in Firefox but in IE and Opera it
works fine.

The div looks like:

<div id="handbookPop>
    some stuff
</div>

Any help would be greatly appreciated - thanks.
web.dev - 28 Feb 2006 19:21 GMT
> function setStyle(element, property, value) {
>  element = document.getElementById(element);
>  if(element.style) {element.style[property] = value;}
> }

[snip]
>     setStyle(handbookPop, 'display', 'none');
>     setStyle(handbookPop, 'display', '');

handbookPop is not defined because you are sending an undefined value
to your function setStyle function.  Change it to the following
accordingly:

setStyle("handbookPop", "display", "none");
setStyle("handbookPop", "display", "");

handbookPop should be a string.

> But when I use a <body onLoad="javascript:hideDiv();">
> <a href="#" onClick="javascript:showDiv();">show div</a>

Javascript pseudo-protocol is a very bad practice.  Try searching the
groups here, and you'll get many reasons as to why it is so.
forwardtrends - 28 Feb 2006 19:51 GMT
Great thank you - your solution worked.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.