Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Easy help needed with item properties

    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, I get an error which Firebug reports as divItem[i] has no properties.

    Here's the code in the .js file:
    Code:
    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
    Code:
    onmouseover="javascript:mouse(X);"
    in the correct place.

    Thoughts?
    Last edited by smcutter; 12-27-2007 at 12:38 AM.

  • #2
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by smcutter; 12-27-2007 at 12:44 AM.

  • #3
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    		<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....

    Code:
    		<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>
    			</ul>
    		</div>
    				
    		<div id="smenu2a" style="display:none;">
    			<ul class="listed">
    			<li><a href="resume.html">Resume</a>
    				 <p class="subpoint">(currently under revision)</p></li>
    			</ul>
    		</div>
    The HTML is pretty straightforward, as is the JavaScript. But for some reason, it ain't workin'.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •