Click to See Complete Forum and Search --> : How to call a function 'onload'


shelton
11-07-2003, 01:59 PM
I am trying to call this function onload:

function dispaySubmenu() {
var display = menuopen.style.display;
this.parentNode.style.backgroundImage = (display == "block") ? "url(i/menminus.gif)" : "url(i/plus.gif)";
menuopen.style.display = (display == "block") ? "none" : "block";

return false;
}

with this:

<script type="text/javascript">
<!--
if(window.location == "http://tlhweb014/council/council2.htm") {
window.onload = function displaySubmenu();
}
//-->
</script>

What's wrong with this - is it the 'window.onload=' ? Thanks for any help.

Charles
11-07-2003, 02:18 PM
Use

<script type="text/javascript">
<!--
if(window.location == 'http://tlhweb014/council/council2.htm') {
window.onload = function () {
var display = menuopen.style.display;
this.parentNode.style.backgroundImage = (display == "block") ? "url(i/menminus.gif)" : "url(i/plus.gif)";
menuopen.style.display = (display == "block") ? "none" : "block";

return false;
}
}
//-->
</script>

or

<script type="text/javascript">
<!--
function dispaySubmenu() {
var display = menuopen.style.display;
this.parentNode.style.backgroundImage = (display == "block") ? "url(i/menminus.gif)" : "url(i/plus.gif)";
menuopen.style.display = (display == "block") ? "none" : "block";

return false;
}

if(window.location == "http://tlhweb014/council/council2.htm") {
window.onload = displaySubmenu;
}
// -->
</script>

or

font=monospace]<script type="text/javascript">
<!--
function dispaySubmenu() {
var display = menuopen.style.display;
this.parentNode.style.backgroundImage = (display == "block") ? "url(i/menminus.gif)" : "url(i/plus.gif)";
menuopen.style.display = (display == "block") ? "none" : "block";

return false;
}

if(window.location == "http://tlhweb014/council/council2.htm") {
window.onload = function () {displaySubmenu()};
}
// -->
</script>[/font]

shelton
11-07-2003, 02:40 PM
Thanks, I used the third option. But... the thing doesn't work.

This page is an example of a second level page called 'Submitting a Proposal' and i'm trying to make the menu retain it's 'state' as one navigates around.

If you feel inclined, here's a link.

http://williamlatimer.com/council/council2.htm

I'm trying to tell the item that is highlighted to display it's submenu (nested ul) and to display it's minus sign as opposed to the plus sign. Then when clicked close up the nested ul.