/    Sign up×
Community /Pin to ProfileBookmark

javascript menu text preload

I have a problem with one of my first javascript projects…
I’m trying to pre-load a text menu, and am fairly new to javascript, so I thought I might post here for some advice.

What is happening is the menu is showing for a moment after the page loads and then hiding. I’d like the menu to preload and just hide until needed.

My header script is:

[CODE]

<script type=”text/javascript”>
<!–
window.onload=show;
function show(id) {
var d = document.getElementById(id);
for (var i = 1; i<=10; i++) {
if (document.getElementById(‘smenu’+i))
{document.getElementById(‘smenu’+i).style.display=’none’;}
}
if (d) {d.style.display=’block’;}
}
//–>

</script>
[/CODE]

and I’m calling it on my page with:

[CODE]
<dt onclick=”javascript:show (‘smenu4’);”>
[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisNov 21.2007 — Get rid of this:window.onload=show;
Copy linkTweet thisAlerts:
@felgallNov 21.2007 — and get rid of the unneeded javascript: label from within your JavaScript.
Copy linkTweet thisAlerts:
@supertoadauthorNov 21.2007 — Get rid of this:window.onload=show;[/QUOTE]


Thank you so much for the reply!


When I remove this, my menus don't hide like they did before - they just show the whole time...

I kinda feel like i'm backpedaling when I should be starting over ?
Copy linkTweet thisAlerts:
@gil_davisNov 22.2007 — You have to make the default for the DIV style "display: none" so that they are hidden when they are written to the document. You could do it by using the id in the css:
&lt;style type="text/css"&gt;
#smenu4 {
display: none;
}
Since you did not post the definition of the DIV involved, I had to make my best guess. If you do something like this, you will not need the onload statement.
×

Success!

Help @supertoad spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...