Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 07-27-2008, 05:18 PM Function problem
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Im trying to code a function that will make the value of a paragraph element equal to the title attribute of an image, whenever the image is hovered.

Basically my script puts every <img> tag into an array, and checks to see if it is inside a div with the id of 'portThumbWebsite'.

if it is in that div, it is supposed to make the paragraph value change so that it is the same as the image's title attribute.

Instead, the onMouseOver event handler just seems to be ignored, and the paragraphs value is just set to be the same as the last index of the array of image titles.

Maybe the code will help to explain!

Code:
// display the name of the project on thumb hover

function thumbChange (thumbTitle)    
    {
        // set pWebsite equal to image title on hover
        pWebsite = document.getElementById ('pWebsite');
        pWebsite.firstChild.nodeValue = thumbTitle;
    }
        
function portTitleDisplay ()
    { 
        // declare variables
        divPortThumb = document.getElementsByTagName ('img');
        thumbId = new Array ();
        thumbTitle = new Array ();

        // loop through thumb id's titles
        num = divPortThumb.length;
            
        // declare index to be used as array indexes
        index = 0;
        for (i = 0; i < num; i ++)
            {
                // only perform in specified div
                divPortThumbId = divPortThumb[i].parentNode.parentNode.parentNode.id;
                
                if (divPortThumbId == 'portThumbWebsite')
                    {
                        thumbId[index] = divPortThumb[i].id;
                        thumbTitle[index] = divPortThumb[i].title;
                        
                        // change value of pWebsite on hover of thumb
                        thumbId[index].onMouseOver = thumbChange (thumbTitle[index]);
                        index ++;
                    }
            }
    }
    
window.onload = portTitleDisplay;
Does anyone know what I might be doing wrong? There appears to be no actual errors in the syntax.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Last edited by pealo86; 07-27-2008 at 05:20 PM..
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 07-28-2008, 09:30 PM Re: Function problem
Extreme Talker

Posts: 238
Location: United States
Trades: 0
One thing I see is that thumbId[index].onMouseOver should be thumbId[index].onmouseover. Event handlers should always be lower-case in JavaScript.
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
frost is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Function problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11120 seconds with 12 queries