Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Javascript functions and css

Author
Message
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 6th Jul 2003 22:13 Edited at: 6th Jul 2003 22:17
I'm not sure if this is inflicting on the forum rules (doesn't support bandwidth for discussions about other products), but javascript isn't really a product like blitzbasic. I'm sure some people around here know some stuff about this...

I am having real problems with a drop down menu, I want to hide or show a division when another division is pressed (ie. a section of a menu dropping down and up), I can do that for one menu by using...

document.all.div.style.display = "none"

But I want to pass a value into a function so that I may use the same function for each menu. This is my code so far...

inside head and script tags...
function menuOnOff(e) {
document.all.e.style.display = "none";
}

inside body tags.....
<DIV class="menuclass" onClick="menuOnOff(mnu1)">Home</DIV>
<DIV id=mnu1 class="menuclass">News</DIV>

I am meaning to pass the value "mnu1" to the function menuOnOff(e), and insert it into the hiding code using the variable "e", but it doesn't work, just comes up with an error on the status bar in the browser. Any ideas?

cuRant PRogekt: a three-de map editer
Why the hell'd you ask me for crying out loud!?!
Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 6th Jul 2003 22:25 Edited at: 7th Jul 2003 01:36
First off , you are wanting to pass a string, so must be in quotes or single quotes:

<DIV class="menuclass" onClick="menuOnOff('mnu1')">Home</DIV>

To use that in function:

function menuOnOff(e) {
var o=eval('document.all.' + e);
o.style.display='none';
}

(above function edited!)

R Tape loading error
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 6th Jul 2003 22:27
P.S. Note that DIV's don't work in all browsers. Older versions of netscape use LAYER tags instead. You will have to use some browser detect code if you want true cross-browser code.

R Tape loading error
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 6th Jul 2003 22:42
Sorry Sonic, still doesn't work. I know that it won't be compatable with all browsers, but before I can get one version to work I dont think I need to worry about that sort of thing.

Here is my whole code, I have looked at loads of tuts on the internet but I really don't get why my functions don't work like theirs do. I would be really grateful if you could see what is wrong !

cuRant PRogekt: a three-de map editer
Why the hell'd you ask me for crying out loud!?!
Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 6th Jul 2003 23:48
Do not worry, I just took the extra "+ '" out of the eval() command and it works fine . Thanks !

cuRant PRogekt: a three-de map editer
Why the hell'd you ask me for crying out loud!?!
Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 7th Jul 2003 01:35
Sorry about that, I nicked it from some javascript on one my work sites that had some extra stuff in it but forgot to remove the spurious characters.

R Tape loading error

Login to post a reply

Server time is: 2024-09-20 05:02:46
Your offset time is: 2024-09-20 05:02:46