Forum Moderators: open

Message Too Old, No Replies

how to add title to image in this javascript

         

Simone100

12:38 am on Aug 12, 2006 (gmt 0)

10+ Year Member



Hello, here is some image javascript I am using to show an image and also a link to a different page when you click on the image.

I need to know how I would show a title for each image when the image is hovered over (like alt)to add to this script. Here is the script as it is now...the "testtitle" is where I am trying to add the image title, just as the image source and image link are added.

arr=[

["image1.gif","page1.htm"],
["image2.gif","page2.htm","testtitle"] // no comma at the end of last index
]

now=new Date()
nowDate=now.getDate()

function changeImg(){

if(nowDate>arr.length){
return
}

document.getElementById("img").src=arr[nowDate-1][0]
document.getElementById("link").href=arr[nowDate-1][1]
document.getElementById("title").title=arr[nowDate-1][2]
}

And this is in the body section of the page...

<BODY onload="changeImg()">

<a href="#" id="link" target="_blank"><img border="0" image id="img"><image title id="title"></a>

As it works right now a small box is next to the image itself and the "testtitle" does show when you hover over the small box. But I would like "testtitle" or (whatever title text I want to use) to show
over the image instead when it is hovered over like it is supposed to.

Hope someone can help, thanks! Simone

Geoffrey james

5:46 am on Aug 12, 2006 (gmt 0)

10+ Year Member



hope this works for you, experts may prove me wrong but as I have never been able to reply to these posts before (mainly as I dont know the answers) here is mine to your question.

try:
<a href="#" id="link" target="_blank" title="testtitle"><img border="0" image id="img"></a>

As you can see I have buried the title inside the a href line, this works fine for me and is quoted as what should be done in text books too dude.

Not sure why you need the <img border="0" image id="img">though!

Geoff

Simone100

7:44 pm on Aug 12, 2006 (gmt 0)

10+ Year Member



Thanks Geoff but here's what I am trying to do. The example I give allows you to have a different image for every day. You input the image source and a url that will lead to another page when the image is clicked on. (Usually a page where you can see the image much larger)as in the site is was found on.

I want the title to change daily along with the rest of these. Sorry I didn't explain that better before you had to look through my code. Even though your answer makes perfect sense and is the usual way, it won't work for changing the title daily along with the rest. Thanks for the help though. Simone

Geoffrey james

6:43 am on Aug 13, 2006 (gmt 0)

10+ Year Member



hey Simone

would like to be able to answer your question, BUT can't...he he!

am sure the experts here will though.

although not too sure why its so important for you to have this box appear anyway dude, it take a second or two for theese to appear and many people wont wait that long, they will just see that the image links somewhere and click it if they want....well I do anyway.

good luck

geoff