Click to See Complete Forum and Search --> : ramdom image code & alt tag


can_add
11-22-2006, 11:23 AM
I'm making a web site and it has a header that is a ramdom image

Now i need to add alt tags to the images, how would i go about doing that?

I think alot of people has seen this code but here it is most of it


var theImages = new Array()

theImages[0] = 'images/head/head1.jpg" width="760" height="142'
theImages[1] = 'images/head/head2.jpg" width="760" height="142'
theImages[2] = 'images/head/head3.jpg" width="760" height="142'
theImages[3] = 'images/head/head4.jpg" width="760" height="142'


var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}

holyhttp
11-22-2006, 04:14 PM
How about creating a corresponding altText array for the alt text:
altText=new Array('alt text0', 'atl text1', 'alt text2', 'alt text3');

in you function you just need to modify the lat statement:

document.write('<img src="'+theImages[whichImage]+'" alt="'+altText[whichImage]+'">');

felgall
11-22-2006, 08:11 PM
Why not just add them to the end of the three attributes already stored in the array.

theImages[0] = 'images/head/head1.jpg" width="760" height="142 alt="some text';

You might also consider adding title="" to your images as well to patch the IE bug where it doesn't handle alt tags correctly.

can_add
11-24-2006, 11:17 AM
How about creating a corresponding altText array for the alt text:
altText=new Array('alt text0', 'atl text1', 'alt text2', 'alt text3');

in you function you just need to modify the lat statement:

document.write('<img src="'+theImages[whichImage]+'" alt="'+altText[whichImage]+'">');

thanks for the help worked great!