Trying to change a image dynamically

M

MarkusJNZ

Hi, I am trying to change an image and it's associated width/ height
dynamically via Javascript.

In my HTML I have declared the following:

<table width="100%" class="details">
<tr>
<td
align="left">
<img id="largeImage" />
</td>
</tr>
</table>

where largeImage is the image I wish to change (Please note images can
be of different sizes)

I then have a javascript function which I call and pass in the name of
the image as well as the new size that I would like the image to be.

e.g.

function showImage(imageName, nHeight, nWidth)
{
document.getElementById('largeImage').src = './_listingImages/' +
imageName;
document.getElementById('largeImage').style.width=nWidth + "px;";
document.getElementById('largeImage').style.height=nHeight + "px;";
}

This does not seem to work at all; In firefox for example the page
length just seems to get bigger and bigger (The images do swap) and in
IE the width and height is just ignored.

Any help appreciated
Thanks
Markus
 
S

scripts.contact

function showImage(imageName, nHeight, nWidth)
{
document.getElementById('largeImage').src = './_listingImages/' +
imageName;
document.getElementById('largeImage').style.width=nWidth + "px;";
document.getElementById('largeImage').style.height=nHeight + "px;";

}


function showImage(imageName, nHeight, nWidth){
var img=document.getElementById('largeImage');
img.src = './_listingImages/' + imageName;
img.style.width=parseInt(nWidth,10)+"px";
img.style.height=parseInt(nHeight,10)+"px";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top