Click to See Complete Forum and Search --> : Javascript calling an image


npereira
07-21-2003, 09:22 AM
Hi,

Here is a javascript that calls images in the b/ and p/
Although, I would like it to print the name of the file on top of each images outputed to html to know which image file name I am looking at.

Here is the code:




<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title></title>
<script language="JavaScript"><!--

// preview numbers for personal category
p = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18);
// previews for business category
b = new Array(1,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30);

// available colors
cp= new Array(5,5,5,5,4,6,5,4,5,9,8,5,7,5,6,6,5,6);
// available colors for business
cb= new Array(5,5,4,4,4,4,4,5,5,4,5,5,6,5,5,5,5,6,6,6,6,6,6,6,6);
function changepic(cat,pic) {
for (i=1;i<=8;i++) {this.parent.frames["bottom"].document.images[i].src="spacer.gif"}
if (cat == "p") {
this.parent.frames["bottom"].document.images["preview"].src="p/preview_"+p[pic]+"_1.jpg";
for (i=1;i<=cp[pic]-1;i++) {
this.parent.frames["bottom"].document.images[i].src="p/preview_"+p[pic]+"_"+(i+1)+".jpg";
}
}
else {
this.parent.frames["bottom"].document.images["preview"].src="b/preview_"+b[pic]+"_1.jpg";
for (i=1;i<=cb[pic]-1;i++) {
this.parent.frames["bottom"].document.images[i].src="b/preview_"+b[pic]+"_"+(i+1)+".jpg";
}
}
}
//--></script>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#000099" vlink="#330066" alink="#FF0000">
<table>
<script language="JavaScript"><!--
for (i=b.length-1;i>=0;i--) {document.write('<td><a name="b'+i+'"></a><a href="#b'+i+'" onclick="java script:changepic('b',''+i+'')"><img src="b/sm/preview_'+b[i]+'_1.jpg" width="80" height="58" alt="" border="1"></a></td>\n');}
for (i=0;i<=p.length-1;i++) {document.write('<td><a name="p'+i+'"></a><a href="#p'+i+'" onclick="java script:changepic('p',''+i+'')"><img src="p/sm/preview_'+p[i]+'_1.jpg" width="80" height="58" alt="" border="1"></a></td>\n');}
//--></script>
</table>
</body>
</html>



For an example, seee this link templates (http://www.npereira.com/templates)

let me know if you can help as I know nothing about javascript but I need only to modify the code to show the image fiel name above it.

Thanks


__________________
Regards,

NPEREIRA