Results 1 to 12 of 12

Thread: OnMouseOver Change Text

  1. #1

    Thread Starter
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268

    Question OnMouseOver Change Text

    Ok, I have no idea whatsoever how to do this, so please be thorough with any instructions.

    On the left, I have a navbar, it has a list of several objects in it. What I want is when the user hovers over an object a table cell filled with text changes to fill with a description of that object. The text stays there even when the user moves the mouse off of the object but will change when the user hovers over a different object.

    Sounds simple, help me out guys!
    Last edited by Zaphod64831; Jul 27th, 2001 at 06:37 PM.
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

  2. #2
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Try this:
    Code:
    <html>
    <head>
    <title></title>
    
    <script LANGUAGE = "JavaScript">
    
    var curCell;
    
    function changeText(tdLink,strDesc){
    
    if(curCell){
    curCell.nextSibling.innerText = '';
    }
    tdLink.nextSibling.innerText = strDesc;
    curCell = tdLink;
    
    }//end function
    </script>
    
    </head>
    <body>
    <table>
    <tr>
    <td NAME = "link1" ONMOUSEOVER = "changeText(this,'This is link1');">Link # 1</td>
    <td NAME = "desc1"></td>
    </tr>
    <tr>
    <td NAME = "link2" ONMOUSEOVER = "changeText(this,'This is link2');">Link # 2</td>
    <td NAME = "desc2"></td>
    </tr>
    </table>
    </body>
    </html>
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  3. #3

    Thread Starter
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268
    This is almost exactly what I'm looking for, thank you. I have one problem though, can you make it so it will change the text in a certain named cell?
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

  4. #4
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Similar to the above:
    Code:
    ...
    
    <script LANGUAGE = "JavaScript">
    
    var curCell;
    
    function changeText(tdLink,strDesc){
    
    if(curCell){
    curCell.innerText = '';
    }
    tdLink.innerText = strDesc;
    curCell = tdLink;
    
    }//end function
    </script>
    
    ...
    
    <table>
    <tr>
    <td NAME = "link1" ONMOUSEOVER = "changeText(desc1,'This is link1');">Link # 1</td>
    <td ID = "desc1"></td>
    </tr>
    <tr>
    <td NAME = "link2" ONMOUSEOVER = "changeText(desc2,'This is link2');">Link # 2</td>
    <td ID = "desc2"></td>
    </tr>
    </table>
    
    ...

    Chris
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  5. #5

    Thread Starter
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268
    Thank you VERY much for your help. Unfortunately I found one more thing I need changed, I came across it earlier and I'm not sure if it's possible in javascript, but is there a way to make the browser format any HTML in the strDesc? It's basically an optional thing, but it would be much appreciated...

    Thanks again!
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

  6. #6
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Instead of using innerText use innerHTML.
    Any string passed to innerHTML will be rendered as HTML
    meaning that you can use any HTML text formatting tags such as <b> and <i>.

    Code:
    ...
    tdLink.innerHTML = strDesc;
    ...
    ONMOUSEOVER = "changeText(desc1,'<b>This is link1</b>');"
    ...
    One final note.
    This is an IE feature. I'm pretty positive that Netscape doesn't support these properties. So if that is an issue you'll have to find another way.

    Chris
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  7. #7

    Thread Starter
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268
    Thank you! Your help is much appreciated!
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

  8. #8
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126
    Not trying to be negative, but I assume you're happy with IE specific code...

  9. #9
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126
    Sorry - I didn't read chris's post properly!!

  10. #10
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604
    i am using this code now, but is there a way to modify the code so that when the mouse moves off of the text that the information dissapears ??

    cheers

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

  11. #11
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Use this:
    Code:
    ONMOUSEOUT = "changeText(this,'');"
    Just pass a empty string for the second argument.
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  12. #12
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604
    cheers mate

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

Posting Permissions

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



Click Here to Expand Forum to Full Width