Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Appear on mouse hover

Status
Not open for further replies.

3allawy

Programmer
Oct 19, 2005
28
CA
Hi,

I would like to know if there is a way to make the text appear once the mouse is on my header image. The following code is used:

document.write('<div id="photo"><img src= " image1.jpg" alt="" width="650" height="106" border="0" /></div>');
 
replace [tt]alt=""[/tt] with [tt]alt="something"[/tt].

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
Hi,

Actually, I have a java script that randomly chooses an image and dispalys is as the header of a website. What I want to do is to have a text appear (image name) when I move the mouse on the image.

var counter = Math.ceil((Math.random() * 6));
var imagepath = "
switch (counter){
case 1:
var case1 = imagepath + "01.jpg"
document.write('<div id="photo"><img src="' + case1 + '" alt="" width="650" height="106" border="0" /></div>');
break;
case 2:
var case2 = imagepath + "02.jpg"
document.write('<div id="photo"><img src="' + case2 + '" alt="" width="650" height="106" border="0" /></div>');
break;
case 3:
var case3 = imagepath + "03.jpg"
document.write('<div id="photo"><img src="' + case3 + '" alt="" width="650" height="106" border="0" /></div>');
break;
case 4:
var case4 = imagepath + "04.jpg"
document.write('<div id="photo"><img src="' + case4 + '" alt="" width="650" height="106" border="0" /></div>');
break;
case 5:
var case5 = imagepath + "05.jpg"
document.write('<div id="photo"><img src="' + case5 + '" alt="" width="650" height="106" border="0" /></div>');
break;
case 6:
var case6 = imagepath + "06.jpg"
document.write('<div id="photo"><img src="' + case6 + '" alt="" width="650" height="106" border="0" /></div>');
break;
default : document.write('<div id="photo"><img src="' + case7 + '" alt="" width="650" height="106" border="0" /></div>');
}
 
so what is it that you did not understand about my post? you are providing the attribute "alt" with a blank string, therefore nothing will show up. provide it with the image's name.

Code:
case 1:
var case1 = imagepath + "01.jpg"
document.write('<div id="photo"><img src="' + case1 + '" alt="[red]' + case1 + '[/red]" width="650" height="106" border="0" /></div>');
break;

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
Thx alot ClFlava....It is working well on IE but not on Firefox....Do u have an idea if there is another attribute I should add for mozilla
 
add title also.

Code:
case 1:
var case1 = imagepath + "01.jpg"
document.write('<div id="photo"><img src="' + case1 + '" alt="' + case1 + '"[red] title="' + case1 + '"[/red] width="650" height="106" border="0" /></div>');
break;

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
I've added title together with alt but still doesnot work...tried title alone...works only on IE
 
I've tried replacing title in the div with the image but still not working...any ideas :)
 
I'd double-check whether you're typing things correctly. I've got it working in IE, Opera, and FF using the alt and title attributes.

Code:
<div id='div1'><img src='Nic1.bmp' alt='Nic1.bmp' title='Nic1.bmp' /></div>

--Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Hi,

Still not working: Can you please verify this line:

document.write('<div id="photo"><img src="' + case1 + '" alt="titleme" title="titleme" width="650" height="106" border="0" /></div>');


Thks,

Ali
 
I tried this:

Code:
<html>
<body>
<script>
var case1 = 'Nic1.bmp';
[b]document.write('<div id="photo"><img src="' + case1 + '" alt="titleme" title="titleme" width="650" height="106" border="0" /></div>');[/b] //your line, exactly
</script>
</body>
</html>

...and it worked for me in IE, Opera, and FF.

Does your image src variable (case1) happen to have a quote in it? I can't think of why else this isn't working for you.

--Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top