Page 1 of 1

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

Posted: Fri Sep 05, 2003 1:40 pm
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.

Posted: Fri Sep 05, 2003 1:43 pm
by Unipus
instead of display: none use visibility: hidden and visibility: visible.

Posted: Fri Sep 05, 2003 2:15 pm
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.

Posted: Fri Sep 05, 2003 2:31 pm
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

Posted: Fri Sep 05, 2003 3:43 pm
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]

Posted: Fri Sep 05, 2003 8:14 pm
by Vincent Puglia
no prob :)