/    Sign up×
Community /Pin to ProfileBookmark

Hiding DIVs that "don’t exist"??

Hi. I’ve been doing Javascript on and off for the past few years, and I’ve been working with a script recently, which just does not want to work.

This is what the page looks like:

[code=php]
<!—– Paul’s Fancy Schmancy Menu Test —>
<html>
<head>
<title>Paul’s Fancy Schmancy Menu Test</title>

<script langauge=”Javascript”>
function showMenu()
{
document.Menu1.style=”position:absolute; TOP:8pt; LEFT:0pt; WIDTH:0pt; HEIGHT:0pt; Z-INDEX:66;”;
}
</script>
</head>

<body>
<div ID=”Menu1″ style=”position:absolute; TOP:8pt; LEFT:0pt; WIDTH:0pt; HEIGHT:0pt; Z-INDEX:44;”>
<table bgcolor=”#000000″ width=”20%”>
<tr>
<td width=”100%”><a href=”javascript: showMenu();”>Hello</a> </td>
</tr>
</table>
</div>

<div id=”Menu2″ style=”position:absolute; visibility:hidden; TOP:8pt; LEFT:0pt; WIDTH:0pt; HEIGHT:0pt; Z-INDEX:55;”>
<table bgcolor=”#000000″ width=”20%”>
<tr>
<td width=”100%”><a href=”Hello.html”>bye</a> </td>
</tr>
</table>
</div>

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

Now, the idea is that when I click ‘Hello’, the table with ‘Bye’ should become visible.

I would swear that this is right, yet for some reason its not working. Instead, I get the error:
document.Menu1 is not an object
So obviousley I am wrong. If anyone could tell me how I can access the style of that DIV any other way, I would be very gratefull.

~ Paul

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@khalidali63Apr 26.2003 — you have the "bye" table in the div tag,thats good,you initially have visibility for this div to be hidden,thats good too,but you are not making it visible at any point,add this line in the function showMenu

document.getElementById("Menu2").style.visibility="visible";
Copy linkTweet thisAlerts:
@stovellpauthorApr 26.2003 — Thankyou sssoooooooooooo much!!! I could have sworn I used getElementById() before, but it didn't work.

lol, thank you very much!

~ Paul
Copy linkTweet thisAlerts:
@stovellpauthorApr 26.2003 — Ahhh, thankyou very much... I understand that now ?

Thanks to your help, I went on to creating my own little menu system. I added a function to hide the table too when it shows:
[code=php]
<!----- Paul's Fancy Schmancy Menu Test --->
<html>
<head>
<title>Paul's Fancy Schmancy Menu Test</title>
<script langauge="Javascript">
//-------------------------------------------
function showMenu()
{
document.getElementById("Menu2").style.visibility="visible";
}
//-------------------------------------------
function hideMenu()
{
document.getElementById("Menu2").style.visibility="hidden";
}
</script>
</head>

<body>

<!------ Menu 1 ---->
<table style="position:absolute; TOP:8pt; LEFT:0pt; WIDTH:0pt; HEIGHT:0pt; Z-INDEX:44;" bgcolor="#000000" width="20%">
<tr>
<td width="100%"><a href="javascript: showMenu()">Menu</a> </td>
</tr>
</table>

<!------ Popup Menu ---->
<DIV id="Menu2" style="position:absolute; visibility:hidden; TOP:8pt; LEFT:0pt; WIDTH:0pt; HEIGHT:0pt; Z-INDEX:55;">
<table bgcolor="#000000" width="30%" onmouseout="hideMenu()">
<tr>
<td width="100%"><a href="Hello.html">Downloads</a></td>
</tr>
<tr>
<td width="100%"><a href="Hello.html">Products</a></td>
</tr>
<tr>
<td width="100%"><a href="Hello.html">Search</a></td>
</tr>
</table>
</DIV>

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


You would have seen these types of menus before, you mouseover and they show, u select a link, etc. You move your mouse away, they hide again. Unfortunately I'm stuck with hiding them.

What I mean it, it hides just fine, but as soon as I move my mouse off any of the links. This is not what I want, I need the table to stay shown until the user selects a link, or moves their mouse away from the table.

I figured that by doing the 'onmouseout' on the table or the DIV, I'd avoid this, but that unfortunately didn't work.

Theres probably a much simpler way to do this, and if there is I would be glad if you could please tell me ?

~ Paul

And thanks for all your help so far, its much appreciated!
Copy linkTweet thisAlerts:
@stovellpauthorApr 26.2003 — Ok, I understood what you were getting at, the width/height restraints I put in were affecting where 'onmouseout' occurs.

I did as you suggested, and got this line:

<DIV id="Menu2" style="position:absolute; visibility:hidden; TOP:25pt; LEFT:0pt; Z-INDEX:55;" onmouseout="hideMenu()">

Unfortunately, the same thing is still occuring, the menu hides as soon as I move the mouse, even if I keep it on the table. ?
Copy linkTweet thisAlerts:
@khalidali63Apr 26.2003 — just add this line in the table elements deffinition

onmouseover="showMenu()" onmouseout="hideMenu()"

so that it looks like

<table bgcolor="#000000" width="30%" onmouseover="showMenu()" onmouseout="hideMenu()" >

An you are set to go
Copy linkTweet thisAlerts:
@stovellpauthorApr 26.2003 — Thankyou very much!! That worked perfectly! I understand it all now, thanks mate! ?
Copy linkTweet thisAlerts:
@stovellpauthorApr 27.2003 — Yes that is what I had before, except I didn't have the 'onmouseover' handler for the table, only mouseout, which is what must have been my mistake ? Thanks very much for helping me with this you guys! ?

~ Paul
×

Success!

Help @stovellp 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.3,
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,
)...