...

View Full Version : image rollover and textbox



chesneil
10-15-2003, 03:57 AM
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>

lavalamp
10-15-2003, 12:22 PM
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 = '';");

chesneil
10-15-2003, 03:05 PM
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

lavalamp
10-15-2003, 06:08 PM
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;">

chesneil
10-15-2003, 06:21 PM
Thanks a lot lavalamp. I think you meant the style goes in the input tag. :thumbsup:

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!

lavalamp
10-15-2003, 08:34 PM
I can't try it on Mac, so i can't help you with that. Happy to help though. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum