Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-14-2006, 07:00 PM   PM User | #1
mat106
New Coder

 
Join Date: Jun 2004
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
mat106 is an unknown quantity at this point
Problem with onmouseout - object has no properties error

Hi all, I've got an image gallery in which users can navigate between the next and previous image by clicking on the right or left half respectively of the current image. When the mouse is over the left half an arrow pointing to the left is shown on the image and when on the right an arrow to the right. It works fine if i use inline javascript but i'm trying to achieve the same effect unobtrusively and with an addEvent function. The onmouseover part works fine but from the function that fires on the onmouseout event i get the following error in Firefox and the arrow is not hidden:
Quote:
document.getElementById("navLeft") has no properties
Source File: http://localhost:8080/.../viewpic.js
Line: 26
This is the relevant html:
Code:
<div class='center'>
<div id='navleft'><a href='previous_pic.jpg'><img src='left.png' alt='' width='34' height='34' border='0' /></a></div>
<img id='mainimage' src='London Zoo-April 2006/pics/img_03.jpg' alt='' usemap='#imagemap' />
<div id='navright'><a href='next_pic.jpg'><img src='right.png' alt='' width='34' height='34' border='0' /></a></div>
</div>
...
<map name='imagemap'>
<area id='left' shape='rect' coords='0,0,216.7,433' href='previous_pic.jpg' />
<area id='middle' shape='rect' coords='216.7,0,433.4,433' />
<area id='right' shape='rect' coords='433.4,0,650,433' href='next_pic.jpg' />
</map>
and this is the javascript:
Code:
window.onload = preparePage;

// Scott Andrew’s addEvent() function.
function addEvent(elm, evType, fn, useCapture) {
    if (elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    }
    else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    }
    else {
        elm['on' + evType] = fn;
    }
}

function showLeftArrow() {
    document.getElementById('navleft').style.display = 'block';
}

function hideLeftArrow() {
    document.getElementById('navLeft').style.display = 'none'; Line 26
}

function preparePage() {
    if(document.getElementById && document.getElementsByTagName){
        document.getElementById('picnav').style.display = 'none';
        
        //add event handlers to image areas.
        var middleSection = document.getElementById('middle');
        addEvent(middleSection, "dblclick", displayImgMetadata, false);
        
        var leftSectionOfImage = document.getElementById('left');
        addEvent(leftSectionOfImage, "mouseout", hideLeftArrow, false);
        addEvent(leftSectionOfImage, "mouseover", showLeftArrow, false);
        
    }
}
mat106 is offline   Reply With Quote
Old 05-14-2006, 08:06 PM   PM User | #2
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,379
Thanks: 3
Thanked 466 Times in 453 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
dont know but I retyped the line and it worked
Code:
function showLeftArrow() {
    document.getElementById('navleft').style.display = '';
}

function hideLeftArrow() {
    document.getElementById('navleft').style.display = 'none';
}
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Old 05-15-2006, 10:09 AM   PM User | #3
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
On the other hand the attachEvent/addEventListener play is an intricate one. I guess that the simple DOM 0 crosbrowser syntax is to be used in this case

object.onmouseover=function(){showLeftArrow()}
object.onmouseout=function(){hideLeftArrow()}
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:13 AM.


Advertisement
Log in to turn off these ads.