/    Sign up×
Community /Pin to ProfileBookmark

Which is this: JS or CSS problem?

Could someone see where I am in error with the following script?
I don’t get errors with FF or IE, but it doesn’t work either.

[code=php]
<html>
<head>
<title>Hide/Show Menu Attempt</title>

<script type=”text/javascript”>
function Show(menu) {
document.getElementById(menu).style.display=”;
}
function Hide(menu) {
document.getElementById(menu).style.display=’none’;
}
</script>

<style type=”text/css”>
.sh {
border:1px solid blue;
display:none;
}
</style>
</head>

<body>
<h1>Hide/Show Menu Attempt</h1>
Test – links to nowhere<br>

<br>
<a href=”#” onMouseover=”Show(‘nsumenu’)”>NSU</a>
<div class=’sh’ id=’nsumenu’><!– onBlur=”Hide(‘nsumenu’)” test later –>
<ul>
<li><a href=”#” onClick=”alert(‘NSU’)”>NSU</a></li>
<li><a href=”#” onClick=”alert(‘Optometry’)”>Optometry</a></li>
</ul>
</div>

<br>
<a href=”#” onMouseover=”Show(‘optmenu’)”>Optometry</a>
<div class=’sh’ id=’optmenu’><!– onBlur=”Hide(‘optmenu’)” –>
<ul>
<li><a href=”#” onClick=”alert(‘Clinic’)”>Clinic</a></li>
<li><a href=”#” onClick=”alert(‘Faculty’)”>Faculty</a></li>
<li><a href=”#” onClick=”alert(‘Students’)”>Students</a></li>
<li><a href=”#” onClick=”alert(‘Staff’)”>Staff</a></li>
</ul>
</div>

<br>
<a href=”#” onMouseover=”Show(‘otmmenu’)”>OTM</a>
<div class=’sh’ id=’otmmenu’><!– onBlur=”Hide(‘otmmenu’)” –>
<ul>
<li><a href=”#” onClick=”alert(‘OTM-1’)”>OTM-1</a></li>
<li><a href=”#” onClick=”alert(‘OTM-2’)”>OTM-2</a></li>
<li><a href=”#” onClick=”alert(‘OTM-3’)”>OTM-3</a></li>
<li><a href=”#” onClick=”alert(‘OTM-4’)”>OTM-4</a></li>
</ul>
</div>

</body>
</html>
[/code]

The attempt is to have hidden <div> until mouse rolls over the initial link.
Later, if I can get the first part to work, I’ll use the onBlur() or onMouseout() to re-hide the display.
Currently, links are non-functional with the alerts set-up to see if concept would work.

Thanks for any replies.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Nov 23.2006 — You need to specify block to show it.

Eric
Copy linkTweet thisAlerts:
@GotMex_Nov 23.2006 — Yup, A1ien51 is right, the JS should read:[code=php]<script type="text/javascript">
function Show(menu) {
document.getElementById(menu).style.display='block';
}
function Hide(menu) {
document.getElementById(menu).style.display='none';
}[/code]
Copy linkTweet thisAlerts:
@JMRKERauthorNov 23.2006 — Thanks Guys,

That worked a lot better than what I originally had.

Now I have a second problem:

When I use onMouseout(), the <div> section closes before I can make a selection.

When I use onBlur(), the <div> section does not close at all.

Do I need to reset all <div> menu sections initially before opening a new section

or is there a better way to make the <div> sections visible until a selection is made

or the <div> section is exited?

Here's the new code:
[code=php]
<html>
<head>
<title>Hide/Show Menu Attempt</title>

<script type="text/javascript">
function Show(menu) {
document.getElementById(menu).style.display='block';
}
function Hide(menu) {
document.getElementById(menu).style.display='none';
}
</script>

<style type="text/css">
.sh {
border:1px solid blue;
display:none;
}
</style>
</head>

<body>
<h1>Hide/Show Menu Attempt</h1>
Test - links to nowhere<br>

<br>
<a href="#" onMouseover="Show('nsumenu')">NSU</a>
<div class='sh' id='nsumenu' onMouseout="Hide('nsumenu')">
<ul>
<li><a href="#" onClick="alert('NSU')">NSU</a></li>
<li><a href="#" onClick="alert('Optometry')">Optometry</a></li>
</ul>
</div>

<br>
<a href="#" onMouseover="Show('optmenu')">Optometry</a>
<div class='sh' id='optmenu' onBlur="Hide('optmenu')">
<ul>
<li><a href="#" onClick="alert('Clinic')">Clinic</a></li>
<li><a href="#" onClick="alert('Faculty')">Faculty</a></li>
<li><a href="#" onClick="alert('Students')">Students</a></li>
<li><a href="#" onClick="alert('Staff')">Staff</a></li>
</ul>
</div>

<br>

<a href="#" onMouseover="Show('otmmenu')">OTM</a>
<div class='sh' id='otmmenu' onMouseout="Hide('otmmenu')">
<ul>
<li><a href="#" onClick="alert('OTM-1')">OTM-1</a></li>
<li><a href="#" onClick="alert('OTM-2')">OTM-2</a></li>
<li><a href="#" onClick="alert('OTM-3')">OTM-3</a></li>
<li><a href="#" onClick="alert('OTM-4')">OTM-4</a></li>
</ul>
</div>

</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@GotMex_Nov 23.2006 — The problem you have has to do with the way events are fired when you move the mouse. In this case, when you move your mouse into the <a> region, the mouseover event fires and you call the Show() function. Then, you move the mouse into the <div> area, which fires the mouseover event on the <div> (which is empty). Here's where the problem happens... when you move your mouse into the <ul> that houses the links, the mouseout event of the <div> fires, then the <ul>'s mouseover event fires, and finally, the mouseover event of the <div> fires again.

So in effect, when you move over the links, you are firing the Hide() function and the div disappears.

Edit: If you add a "onMouseover="Show('nsumenu')"" listener to the <div>'s, they stay open until you actually move the mouse out of the complete div. Not sure how "correct" this solution is, but it works.
×

Success!

Help @JMRKER 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...