...

View Full Version : Replacing One Image For Another with Javascript



skooliano
12-20-2005, 09:24 PM
I am very new to javascript but I am running into an issue with a confirmation page I am building for a registration site. The default for the confirmation is to show all questions and user responses given. A colleague of mine used an image with an image map to create the selections. What happens is the confirmation page spews out the image along with all the other responses.

Is there a way in javascript to exchange one image for another and to set the height and width parameters for the image that your replacing with?

skooliano
12-21-2005, 12:48 AM
Nevermind everyone. I got it. Function below.

<SCRIPT>
function hideGraphics()
{
hideImage(' THE IMAGE LOCATION HERE ');
}
function hideImage(url)
{
if (document.images){for(i=0;i<document.images.length;i++)
{
if(document.images[i].src==url)
{
document.images[i].height=1;
document.images[i].src==' IMAGE YOU WANT TO PUT IN PLACE ';
}
}
}
}
</SCRIPT>

Kor
12-21-2005, 11:48 AM
you may make it simplier and DOM compliant:


<script type="text/javascript">
function changeImg(){
var imag = document.getElementsByTagName('img');
for(var i=0;i<imag.length;i++){
if(imag[i].getAttribute('src')=='THE IMAGE LOCATION HERE'){
imag[i].removeAttribute('height');
imag[i].setAttribute('src','IMAGE YOU WANT TO PUT IN PLACE');
}
}
}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum