dropmenu script (i got one written but doesn't work) ...

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
zick
Forum Commoner
Posts: 33
Joined: Thu Aug 14, 2003 3:18 pm

dropmenu script (i got one written but doesn't work) ...

Post by zick »

ok, i know there are thousands of articles out there that discuss how to do this ... but i follow what they say and it doesn't work. the article i based my script off of is:
http://hotwired.lycos.com/webmonkey/01/ ... =authoring . i'm writing a function to turn on or off a dropmenu represented by a div with the style property "display:none". simple enough, i thought to myself when i started.
well here's my sitch ... and here's some related code:
sample link that would make menu:
<a href="#" onMouseOver="menuOn(company);return true">Company</a>

note the function menuOn() ... here's that function:
function menuOn(obj) {
if (document.all) { // if IE
obj.style.display = 'block';
} else if (document.getElementById) { // if mozilla
document.getElementById(obj).style.display = 'block';
}}

the ie chunk works correctly (using ie 6). the problem is the mozilla chunk. i'm using firebird 0.5 ... and the function as is doesn't work. here's the kicker though, it works as is w/o modification if my link looks like this:
<a href="#" onMouseOver="menuOn('company');return true">Company</a> NOTE: the single quotes around the argument, but of course that won't work in ie.

so you can see the pickle i'm in ... without doing like a document.write to rewrite the entire page, anyone got a suggestions to this problem. thanks for any feedback guys.
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

instead of display: none use visibility: hidden and visibility: visible.
zick
Forum Commoner
Posts: 33
Joined: Thu Aug 14, 2003 3:18 pm

Post by zick »

i'll give that a rogerring ... my guess is that it wont work though. my problem seems to be in the fact that mozilla requires single quotes around the argument when called and ie doesn't ... but ie doesn't ignore the quotes. so i can't just leave them in.
User avatar
Vincent Puglia
Forum Commoner
Posts: 67
Joined: Thu Sep 04, 2003 4:20 pm
Location: where the World once stood

Post by Vincent Puglia »

Hi,

You've run across one of IE's "features" (created for javascript newbies)

It worked because IE was automatically inserting the DOM for you. The following will work with "menuOn('company'). BTW: the 'getEle..." also works for IE. Today, 'document.all' is primarily for backward compatibility (IE 4)

function menuOn(divID) {
if (document.all) { // if IE
document.all[divID].style.display = 'block';
} else if (document.getElementById) { // if mozilla
document.getElementById(divID).style.display = 'block';
}}
<div id='company' style='display:none'>
this is the block
</div>

Vinny
zick
Forum Commoner
Posts: 33
Joined: Thu Aug 14, 2003 3:18 pm

Post by zick »

thanks vince ... you got it.
i'm not really a javascript newbie, i just don't use it very much. rollovers are about all i use. everything else i can do in php (server-side) or something.
that's interesting to learn that document.all is just for back-compat, i never knew that. cool man and thanks again.[/i]
User avatar
Vincent Puglia
Forum Commoner
Posts: 67
Joined: Thu Sep 04, 2003 4:20 pm
Location: where the World once stood

Post by Vincent Puglia »

no prob :)
Post Reply