Click to See Complete Forum and Search --> : Images in tables?


wimmer
10-16-2009, 01:45 AM
Using Dreamweaver 3
I have what maybe an easy question (for you all anyway). I have a simple table with items on the left in plain text, I wish when an item description is clicked, that a corresponding photograph appears in the same table in the main cell on the right. I would like it to remain there until another items text is clicked, and then the image of that item to be replaced etc. Hopefully someone will be kind enough to explain this to me. Many thanks.

Dave Lane
10-16-2009, 11:06 PM
Hi wimmer,

I hope this example code helps:

<table>
<tr>
<td>
<a href="#" onclick="showA();">Show A</a><br />
<a href="#" onclick="showB();">Show B</a>
</td>
<td>
<div id="imageDiv"> </div>
</td>
</tr>
</table>

<script type="text/javascript">
function showImage( imageFilename ){

// replace the imageDiv's HTML with the desired image tag.
var imageDiv = document.getElementById( 'imageDiv' );
imageDiv.innerHTML = '<img src="' + imageFilename + '" />';
}

function showA(){

showImage( 'imageA.jpg' );
}

function showB(){

showImage( 'imageB.jpg' );
}
</script>

The "imageDiv" DIV tag is a placeholder; the showImage() javascript function replaces the contents of the DIV tag.