Richard said:
Here is a possibility.
The code may be a little hard to follow because it uses document.write
to generate the html. I did this because I got tired of typing out all
the long web addresses. To see the generated html, look for the term
one liner in this forum. The one line javascript program will show you
the generated html.
Some of the url's are long. Hope they come out.
Robert
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Swap images</title>
<style type="text/css">
#footer{
clear: both;
padding-left: 20px;
padding-right: 20px;
padding-top: 5px;
padding-bottom: 5px;
background: #eee;
}
..hide { display: none }
</style>
<script type="text/javascript">
var nasaPath = "
http://spaceplace.nasa.gov" +
"/en/educators/images/solarsystem/";
var imageCount = 0;
/* I am using NASA images.
The thumbs have the suffix _T
The full size image has the suffix _L
I pass the image name without the path and the suffix.
To indicate the first call, I pass three arguements. In
the first call, I do not generate the tr tags.
*/
function genImage(link,rollover,msg)
{
// The first row has the full size image, so the
// tr tag is coded below.
// For the second image and all further images, code
// the tr tags.
if (arguments.length == 3)
{ document.writeln("<tr>");}
var data = "<td width='110' valign='top'>" +
"<a href='" + nasaPath + link + "_L.jpg'>\n" +
"<img id='image" + imageCount + "'" +
"src='" + nasaPath + link + "_T.jpg'\n" +
"onclick='return changeImg(\"" +
nasaPath + link + "_L.jpg\",\"" + msg + "\");'\n" +
"onmouseover='setThumb(\"image" + imageCount +
"\",\"" + nasaPath + rollover + "_T.jpg\")'\n" +
"onmouseout='setThumb(\"image" + imageCount +
"\",\"" + nasaPath + link + "_T.jpg\")'\n" +
">\n" +
"<\/a></td>";
imageCount++
document.writeln(data);
// End tr tag
if (arguments.lenght == 3)
{ document.writeln("<\/tr>");}
}
function changeImg(name,msg)
{
document.images["big_image"].src =
"
http://spaceplace.jpl.nasa.gov/en/_images/common/nasa_header/logo_nasa.g
if";
document.images["big_image"].src = name;
changeText('text',msg);
return false;
}
function setThumb(id,name)
{
document.images[id].src = name;
}
function changeText(label,text)
{
var node;
if (document.getElementById)
{
var node = document.getElementById(label);
if (node)
{
node.innerHTML = text;
return; /*See if we already inserted a node. */
}
else
{
alert("You need to create a span tag with " +
"the id of " + label + ".");
return;
}
}
else
{
alert(" document.getElementByID failed. " +
"You need to use a newer browser.");
return;
}
}
</script>
</head>
<body>
<h1 style="text-align: center;">Solar System</h1>
<table>
<tr>
<script type="text/javascript">
genImage("Mercuryglobe1","Mercuryglobe2","Planet Mercury","first");
</script> <td width="600" height="800" align="center" valign="top"
rowspan="7">
<img id="big_image"
src="
http://spaceplace.jpl.nasa.gov/en/_images/common/nasa_header/logo_nasa.gi
f"<br><span id='text'>Replacement text here...</span>
</td>
</tr>
<script type="text/javascript">
genImage("Venus","venusglobe","Planet Venus");
genImage("clem_full_moon","Earth_moon","Earth's moon");
</script> </table>
<div id="footer">
<p>These image are from NASA. See:<br>
http://spaceplace.jpl.nasa.gov/en/educators/teachers_ss_images.shtml
</p>
</div>
<script type="text/javascript">
// Preload the rollover images.
var selimage = new Image();
selimage.src = nasaPath + "Mercuryglobe2_T.jpg";
var selimage = new Image();
selimage.src = nasaPath + "venusglobe_T.jpg";
var selimage = new Image();
selimage.src = nasaPath + "Earth_moon_T.jpg";
var selimage = new Image();
selimage.src = nasaPath + "marsglobe3_T.jpg";
</script>
</body>
</html>