View Full Version : Easy help needed with item properties

12-27-2007, 12:09 AM
Hello all. I've been a casual JavaScript coder for many years now and have never come across a problem that is so elusive yet probably very easy to fix. When I use the following code on my homepage (http://www.sethcutter.com), I get an error which Firebug reports as divItem[i] has no properties.

Here's the code in the .js file:

function mouse(over) {
var divItem = new Array(11);
divItem[1] = document.getElementById('smenu1a');
divItem[2] = document.getElementById('smenu1b');
divItem[3] = document.getElementById('smenu2a');
divItem[4] = document.getElementById('smenu2b');
divItem[5] = document.getElementById('smenu3a');
divItem[6] = document.getElementById('smenu3b');
divItem[7] = document.getElementById('smenu4a');
divItem[8] = document.getElementById('smenu4b');
divItem[9] = document.getElementById('countdown');
divItem[10] = document.getElementById('smenu5a');
divItem[11] = document.getElementById('smenu5a'); // intentional duplicate

for (i=1; i<=10; i=i+1) {
divItem[i].style.display = 'none';

if (over!=0) {
divItem[over].style.display = 'block';
divItem[over+1].style.display = 'block';
divItem[9].style.display = 'none';

if (over==0) {
divItem[9].style.display = 'block';

The HTML has all of the element ID's properly included (I'll post a sample momentarily). Within the HTML is
onmouseover="javascript:mouse(X);" in the correct place.


12-27-2007, 12:13 AM
Also, I know that having the variable definition for each <div> is inefficient... I inserted it there for the purpose of troubleshooting. Normally it's only in a script that runs immediately after the HTML has loaded.

12-27-2007, 12:43 AM
Here's the HTML from my homepage. Like I said, I'm pretty sure the problem is in the JavaScript but hopefully this will help any kind soul who spots a quick issue.

<h2 onmouseover="javascript:mouse(3);">Professional</h2>
<h2 onmouseover="javascript:mouse(1);">Personal</h2>
<h2 onmouseover="javascript:mouse(5);">Publications</h2>
<h2 onmouseover="javascript:mouse(7);">Web Design</h2>

and later on down the page....

<div id="smenu1a" style="display:none;">
<ul class="listed">
<li><a href="http://www.xanga.com/sethicus">Personal Blog</a>
<li><a href="/gallery">Photo Gallery</a></li>

<div id="smenu2a" style="display:none;">
<ul class="listed">
<li><a href="resume.html">Resume</a>
<p class="subpoint">(currently under revision)</p></li>

The HTML is pretty straightforward, as is the JavaScript. But for some reason, it ain't workin'.