jims
04-16-2005, 01:15 PM
I am trying to capture and display the filename of the last image clicked. I have a routine that combines JavaScript and PHP to change out an image preview by clicking on thumbnails (all done with one page), but I can't figure out how to change the text below the preview to match the file name of the last image clicked. Is there a way in JavaScript to retrieve and display the Last Image Clicked filename (without refreshing the page)?
Sample of my gallery so far - just one page, two folders of images and the php automatically catalogs the folders to make the gallery on-the-fly.
Sample Gallery #1 (http://jsinteractive.com/gallery/php-gallery5.php)
Full code below-------------
function changeImage(filename)
{
document.mainimage.src = filename;
}
</script>
</head>
<body bgcolor="#808080">
<div style="overflow:auto; width:100%; height:190px;">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<?php
$pathth = "thumbnails/";
$path = "images/";
if (strrpos($moverse,'..')) {
$moverse = str_replace('/..','',$moverse);
$moverse = substr($moverse,0,strrpos($moverse,'/'));
}
if($moverse) $moverse = $moverse."/";
echo $moverse.'<br>';
$handle=opendir($path.$moverse);
while ($file = readdir($handle)) {
if(is_dir($path.$moverse.$file) && $file != ".") {
if ($file == ".." && $moverse == "") {
} else {
echo '
<td><a href="javascript:changeImage.(\''.$moverse.$file.'\')"><img border="0"
src="'.$pathth.$moverse.$file.'" class="images"> '.$moverse.$file.' </a></td>';
}
} else if ($file != ".") {
echo '
<td><a href="javascript:changeImage(\''.$path.$moverse.$file.'\')"><img border="0"
src="'.$pathth.$moverse.$file.'" class="images"> '.$moverse.$file.' </a></td>';
}
}
?>
</tr>
</table>
</div>
<p align="center"> <img name="mainimage" src="images/001.gif" width="400" height="300"></p>
<script>
document.write(mainimage.src)
</script>
<p align="center">
Image's name or number here
</p>
Sample of my gallery so far - just one page, two folders of images and the php automatically catalogs the folders to make the gallery on-the-fly.
Sample Gallery #1 (http://jsinteractive.com/gallery/php-gallery5.php)
Full code below-------------
function changeImage(filename)
{
document.mainimage.src = filename;
}
</script>
</head>
<body bgcolor="#808080">
<div style="overflow:auto; width:100%; height:190px;">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<?php
$pathth = "thumbnails/";
$path = "images/";
if (strrpos($moverse,'..')) {
$moverse = str_replace('/..','',$moverse);
$moverse = substr($moverse,0,strrpos($moverse,'/'));
}
if($moverse) $moverse = $moverse."/";
echo $moverse.'<br>';
$handle=opendir($path.$moverse);
while ($file = readdir($handle)) {
if(is_dir($path.$moverse.$file) && $file != ".") {
if ($file == ".." && $moverse == "") {
} else {
echo '
<td><a href="javascript:changeImage.(\''.$moverse.$file.'\')"><img border="0"
src="'.$pathth.$moverse.$file.'" class="images"> '.$moverse.$file.' </a></td>';
}
} else if ($file != ".") {
echo '
<td><a href="javascript:changeImage(\''.$path.$moverse.$file.'\')"><img border="0"
src="'.$pathth.$moverse.$file.'" class="images"> '.$moverse.$file.' </a></td>';
}
}
?>
</tr>
</table>
</div>
<p align="center"> <img name="mainimage" src="images/001.gif" width="400" height="300"></p>
<script>
document.write(mainimage.src)
</script>
<p align="center">
Image's name or number here
</p>