Forum Moderators: open

Message Too Old, No Replies

Calling function from onload -- naming problem

onload="toggleMenu(document.all.museum.button.buttonlabel)";

         

gmyachtsman

4:14 am on Dec 20, 2002 (gmt 0)



I need to call a javascript function in a <body onload function. I've figured out that I need to call the same one that is called by onclick here:

<div id="museum" class="button" >
<span style="cursor: hand" class="buttonlabel" onclick='toggleMenu(this)'>
<img src='../index_images/menu/closed-menu.gif'
title='click for museums'
longdesc=''>Museums</span>
</div>

But I can't figure out the right combination of id's, classes, and other attributes to replicate the 'togglemenu(this)' call.

I've tried things like this:

onload="toggleMenu(document.all.museum.button.buttonlabel)";

and this

<BODY onload="toggleMenu(document.all.button.buttonlabel='museum')";

without success and to some extent by trial and error.

The reason I need this is so the menu tree on a webpage will pre-open on one topic like "museums", while leaving the others closed (instead of loading with them all closed). But the java script is very complex and I don't want to work it all out (plus it was all provided on one line, making it hard to read).

tedster

7:33 am on Dec 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try this:

<BODY onload="toggleMenu('museum')";>

gmyachtsman

3:21 pm on Dec 20, 2002 (gmt 0)



Thanks, that worked. So simple!

It didn't make the menu open....but after a little diagnotics I found the activateMenu(id) function that does make the menu open!

(In order not to waste your time (and any more of mine) in case the function wasn't doing what I thought it would I put an

alert("toggleMenu has been called");

line into the javascript so that I could be sure when it was being called by onload).