Click to See Complete Forum and Search --> : Load Different Images on Same Page


meat_spatula
12-12-2002, 12:56 AM
The home page I am trying to make will have an image that is randomly selected from a folder and can be refreshed by clicking on the image. I have done this part and it works. However, I would like the viewer to be able to view a 'specific' image from this folder by clicking on a particular number below the image. Is it possible to do this so that when they go to one of these images by clicking on the number it does not just load the .jpg in that space but still stays on that page except with the image they selected. Any help would be awesome. Hopefully this makes sense.

AdamGundry
12-12-2002, 01:37 PM
If you have hyperlinks under the image as the numbers, you can do something like this (assuming the image is called ChangeImg):

<a href="javascript:ChangeImg.src = 'someimage.jpg'">1</a>

This changes the source of the image to someimage.jpg.

Good luck

Adam

meat_spatula
12-13-2002, 12:53 AM
I am not able to get it working using your help above. I will post the code so that you can see what I am doing wrong, hopefully. The link from '0' doesn't do anything and says error on page, while the link from '1' just refreshes with a random image. How can I make it so that when I click on the '0' it just shows that image(00.jpg)? Please Help!


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!--

<!-- Begin
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = 'index_random/00.jpg'
theImages[1] = 'index_random/01.jpg'
theImages[2] = 'index_random/02.jpg'
theImages[3] = 'index_random/03.jpg'
theImages[4] = 'index_random/04.jpg'
theImages[5] = 'index_random/05.jpg'
theImages[6] = 'index_random/06.jpg'
theImages[7] = 'index_random/07.jpg'
theImages[8] = 'index_random/08.jpg'
theImages[9] = 'index_random/09.jpg'
theImages[10] = 'index_random/10.jpg'
theImages[11] = 'index_random/11.jpg'
theImages[12] = 'index_random/12.jpg'
theImages[13] = 'index_random/13.jpg'
theImages[14] = 'index_random/14.jpg'
theImages[15] = 'index_random/15.jpg'
theImages[16] = 'index_random/16.jpg'
theImages[17] = 'index_random/17.jpg'
theImages[18] = 'index_random/18.jpg'
theImages[19] = 'index_random/19.jpg'
theImages[20] = 'index_random/20.jpg'
theImages[21] = 'index_random/21.jpg'
theImages[22] = 'index_random/22.jpg'
theImages[23] = 'index_random/23.jpg'
theImages[24] = 'index_random/24.jpg'
theImages[25] = 'index_random/25.jpg'
theImages[26] = 'index_random/26.jpg'
theImages[27] = 'index_random/27.jpg'
theImages[28] = 'index_random/28.jpg'
theImages[29] = 'index_random/29.jpg'
theImages[30] = 'index_random/30.jpg'
theImages[31] = 'index_random/31.jpg'
theImages[32] = 'index_random/32.jpg'
theImages[33] = 'index_random/33.jpg'
theImages[34] = 'index_random/34.jpg'
theImages[35] = 'index_random/35.jpg'
theImages[36] = 'index_random/36.jpg'
theImages[37] = 'index_random/37.jpg'

// do not edit anything below this line

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]+'">');
}

// End -->
//-->
</script>

<script>
function reloadMe()
{
window.location.reload()
}
</script>
<script>
<!--
timerID = window.setTimeout ("reloadMe()", 30000)

function MM_displayStatusMsg(msgStr) { //v2.0
status=msgStr;
document.MM_returnValue = true;
}
//-->
</script>

<style type="text/css">
<!--
a:link { text-decoration: none}
.unnamed1 { color: #999999; text-decoration: none}
-->
</style></head>

<body bgcolor="#FFFFFF" topMargin=0 marginheight="0"
marginwidth="0" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
<table width="56%" border="0" height="37">
<tr>
<td height="7"><a href="pictures_02.htm" target="bottom" onClick="MM_displayStatusMsg('?');return document.MM_returnValue">
<script language="JavaScript">

<!-- Begin
showImage();
// End -->
</script>
</a></td>
</tr>
<tr>
<td height="2">
<pre><font color="#999999" face="Verdana, Arial, Helvetica, sans-serif" size="-1"><a href="javascript:pictures_02.theImages.src = 'index_random/00.jpg'" class="unnamed1">0</a> <a href="pictures_02.htm?showimage('01.jpg');" class="unnamed1">1</a> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
</font></pre>
</td>
</tr>
</table>
</body>
</html>

AdamGundry
12-13-2002, 03:22 PM
In order to change the image dynamically, you have to name the image, then refer to it using that name (sorry I wasn't clearer on this last time). So you would have something like this for each link:


document.write('<img name="ChangeImg" id="ChangeImg" src="'+theImages[whichImage]+'">');

<a href="javascript:ChangeImg.src = 'index_random/00.jpg'" class="unnamed1">0</a>


The code for link "1" will simply reload the page with a query string of the image you want, which is not useful. You should be able to use the code above for all the links.

Adam

meat_spatula
12-15-2002, 05:48 PM
I am sorry, but I still can't get this to work, keep in mind I don't really have any clue what this language means, it is the first time I have tried any of this stuff. I put this part of the code in and didn't change any of it:

<a href="java script:ChangeImg.src = 'index_random/00.jpg'" class="unnamed1">0</a>

Here is where I am not sure what is going on. Where do I put this part of the code?

document.write('<img name="ChangeImg" id="ChangeImg" src="'+theImages[whichImage]+'">');

I tried posting both parts together where the link is, but that didn't work. Is the document.write part suppossed to go in a different place as the <a href....> part? Is it suppossed to look something like this and go in the script section:

<script>
document.write('<img name="ChangeImg" id="ChangeImg" src="'+theImages[0] = 'index_random/00.jpg'+'">');
</script>

Also, have I am not sure if and when to plug information into the script you provided?

Help Please, I really appreciate the quick help you have been providing, I just don't know enough about this language to actually make it work. Thanks.

AdamGundry
12-20-2002, 02:03 PM
Sorry if I wasn't clear enough. Try this:


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!--
// Begin
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = 'index_random/00.jpg'
theImages[1] = 'index_random/01.jpg'
theImages[2] = 'index_random/02.jpg'
theImages[3] = 'index_random/03.jpg'
theImages[4] = 'index_random/04.jpg'
theImages[5] = 'index_random/05.jpg'
theImages[6] = 'index_random/06.jpg'
theImages[7] = 'index_random/07.jpg'
theImages[8] = 'index_random/08.jpg'
theImages[9] = 'index_random/09.jpg'
theImages[10] = 'index_random/10.jpg'
theImages[11] = 'index_random/11.jpg'
theImages[12] = 'index_random/12.jpg'
theImages[13] = 'index_random/13.jpg'
theImages[14] = 'index_random/14.jpg'
theImages[15] = 'index_random/15.jpg'
theImages[16] = 'index_random/16.jpg'
theImages[17] = 'index_random/17.jpg'
theImages[18] = 'index_random/18.jpg'
theImages[19] = 'index_random/19.jpg'
theImages[20] = 'index_random/20.jpg'
theImages[21] = 'index_random/21.jpg'
theImages[22] = 'index_random/22.jpg'
theImages[23] = 'index_random/23.jpg'
theImages[24] = 'index_random/24.jpg'
theImages[25] = 'index_random/25.jpg'
theImages[26] = 'index_random/26.jpg'
theImages[27] = 'index_random/27.jpg'
theImages[28] = 'index_random/28.jpg'
theImages[29] = 'index_random/29.jpg'
theImages[30] = 'index_random/30.jpg'
theImages[31] = 'index_random/31.jpg'
theImages[32] = 'index_random/32.jpg'
theImages[33] = 'index_random/33.jpg'
theImages[34] = 'index_random/34.jpg'
theImages[35] = 'index_random/35.jpg'
theImages[36] = 'index_random/36.jpg'
theImages[37] = 'index_random/37.jpg'

// do not edit anything below this line

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 name="ChangeImg" id="ChangeImg" src="'+theImages[whichImage]+'">');
}

// End -->
//-->
</script>

<script>
function reloadMe()
{
window.location.reload()
}
</script>
<script>
<!--
timerID = window.setTimeout ("reloadMe()", 30000)

function MM_displayStatusMsg(msgStr) { //v2.0
status=msgStr;
document.MM_returnValue = true;
}
//-->
</script>

<style type="text/css">
<!--
a:link { text-decoration: none}
.unnamed1 { color: #999999; text-decoration: none}
-->
</style></head>

<body bgcolor="#FFFFFF" topMargin=0 marginheight="0"
marginwidth="0" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
<table width="56%" border="0" height="37">
<tr>
<td height="7"><a href="pictures_02.htm" target="bottom" onClick="MM_displayStatusMsg('?');return document.MM_returnValue">
<script language="JavaScript">

<!-- Begin
showImage();
// End -->
</script>
</a></td>
</tr>
<tr>
<td height="2">
<pre><font color="#999999" face="Verdana, Arial, Helvetica, sans-serif" size="-1<a href="javascript:ChangeImg.src = 'index_random/00.jpg'" class="unnamed1">0</a>
<a href="javascript:ChangeImg.src = 'index_random/01.jpg'" class="unnamed1">1</a> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
</font></pre>
</td>
</tr>
</table>
</body>
</html>


You should also be able to combine the multiple <script> tags into one script, but get it working first :).

Good luck

Adam

meat_spatula
12-26-2002, 05:36 PM
Adam, I am still having problems. I pasted the exact code above in you last post but still isn't working. There is not a link for the '0' and the </a> part is highlighted in yellow in Dreamweaver. The link for the '1' just says 'The Page Cannot Be Displayed'. I am not sure what is wrong here. Help please.

AdamGundry
12-29-2002, 02:16 PM
I've seriously cleaned up and tested the following, it works as far as I can see. Place the first script section where you want the image, and the second where you want the links.


<html>
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<script type="text/javascript">
var MaxImgNumber = 37;
var r = Math.round(Math.random()*(MaxImgNumber-1));
document.write('<a href="' + document.location + '">');
document.write('<img name="ChangeImg" id="ChangeImg" src="index_random/' + r + '.jpg"></a>');
</script>


<script type="text/javascript">
for (i=0;i<=MaxImgNumber;i++){
document.write('<a href="javascript:;" onclick="SetImg(' + i + ');">' + i + '</a> ');
}

function SetImg(imgnum){
ChangeImg.src = "index_random/" + imgnum + ".jpg"
}
</script>

</body>
</html>


I'm wondering if Dreamweaver could be messing the code up - try pasting straight into a text editor?

Adam