Click to See Complete Forum and Search --> : style.display object


JScriptUser
07-22-2003, 01:08 PM
Hi, everyone!

I'd like to create a menu that folds and unfolds with onmouseover and onmouseout. Display worked with functions but visibility didn't. Anyway, my problem is that theDiv.style.display needs an object in hidemenu functon. Isn't style an object? I don't understand what it means. Showmenu and hidemenu worked just fine with this method, but it didn't recognise its object once I included wait function that delays the execution of hidemenu.

Here is the code. Do you know why it does not work? :?:


<script LANGUAGE="JavaScript" TYPE="text/javascript">

function showmenu(id)
{
alert("in showmenu");
var theDiv;
theDiv = document.getElementById(div);
theDiv.style.display="block";
}

function hidemenu(id)
{
var theDiv;
theDiv = document.getElementById(div);
theDiv.style.display="none";
alert("hidden");
}

function wait(div)
{
window.setTimeout("hidemenu('div')",1000);
}
</script>

******* In <html> **********
<td bgcolor="#990000" width="68" onMouseOver="showmenu('InfoFor');" onMouseOut="wait('InfoFor');"><div align="center"><font color="#FFCC99" size="1" face="Verdana"><strong>
Info For</strong></font></td>


The error says, object is required for theDiv.style.display="none"; inside of hidemenu function.

This is another question that I've been trying to get an answer for.
How is menu implemented in JavaScript in general?
I've looked at some examples and I found one that uses addMenuItem and instantiates menu like new Menu(). Of course, showing and hiding div is another way to do this. I heard that array is a good way to store the menu items. I'm not sure how and where they use array to do this. My guess is that arrays are initialized and instantiated in the beginning and each menu item is referenced with array in div. Anyway, I want to find out how to create a user-friendly and Netscape compatible menu.

What is the most general and easy way to implement it?

Have a good day, everyone!

Khalid Ali
07-22-2003, 01:11 PM
seems like you did not define a div aelement with the attribute id="theDiv"

JScriptUser
07-23-2003, 10:10 AM
Hi!

Thanks for your comment but I actually defined div id as InfoFor in <div> section of the code.


<div id="InfoFor" style="position:absolute; top:70px; left:100px; width:200px; display:none; height:20px;">
<p><font size="1" face="Verdana"><a href="http://www.nmsu.edu">Students & Alumni</a></font></p>
<p><font size="1" face="Verdana"><a href="http://www.nmsu.edu">Faculty</a></font></p>
<p><font size="1" face="Verdana"><a href="http://www.nmsu.edu">Employers</a></font></p>
</div>


I think that I need to revise a function wait because that's where the problem is.

Could you take a look at it once more and see if you can fix it please?

I'd appreciate your help! :)