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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    image rollover and textbox

    I have the code below. When the user puts the mouse over a picture some text appears in the textbox below. For some reason it doesn't work. I thought it was pretty easy...

    I'd appreciate if someone could help me out. Thanks

    Here's the code:

    <script language="JavaScript">

    var isReady = false;

    function showTitle(which,what){
    if (isReady){
    document.fm.which.value = what;
    }
    }

    function clearTitle(which){
    if (isReady){
    document.fm.which.value = '';
    }
    }

    </script>

    </head>

    <body onload="isReady=true">
    <form name="fm">
    <table><tr><td>
    <img src="images/desktop.gif" onMouseOver="showTitle(desktop,'Titile One')" onMouseOut="clearTitle(desktop)"><br>
    <input type="text" size="60" name="desktop">
    </td><td>
    <img src="images/laptop.gif" onMouseOver="showTitle(laptop,'Title Two')" onMouseOut="clearTitle(laptop)"><br>
    <input type="text" size="60" name="laptop">
    </td></tr></table>
    </form>
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It doesn't work because "which" is not the name of a field of a form, whereas, the way you have coded it that is the way JavaScript interprets it. Try this:

    eval("document.fm."+which+".value = what;");

    and:

    eval("document.fm."+which+".value = '';");
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many thanks for your help. It didn't work, but by trial and error I found I needed to put inverted commas around 'desktop' and 'laptop' in the onMouseOver / onMouseOut calls in the image tags (as well as what you suggested).

    While I'm here I have another question, though it isn't Javascript. How do I center the text that shows up on mouseover in the textbox? I'd really appreciate any help.

    Thanks

  • #4
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could try doing this for the input tags:

    <img src="images/laptop.gif" onmouseover="showTitle('laptop','Title Two');" onmouseout="clearTitle('laptop');" style="text-align:center;">
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot lavalamp. I think you meant the style goes in the input tag.

    I tried that and it didn't work. Then I discovered it's only on my Mac it doesn't work... Fine in Windows.

    Appreciated!

  • #6
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't try it on Mac, so i can't help you with that. Happy to help though.
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150


  •  

    Posting Permissions

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