Jump to content

[SOLVED] Image Swap using innerHTML


laPistola

Recommended Posts

My JS code

 

<script type="text/javascript">
<!--
function picChange(id,pn) {
var newcode = "<img src=\"images/testimonials/";
var newcode += pn;
var newcode += "\" height=\"300\" alt=\"Before After Pictures\" />";
document.getElementById(id).innerHTML = newcode;
}
//-->
</script>

 

Once PHP has worked its magic the link code comes out like

 

<a href='javascript:picChange('tp2','france_006.JPG')'><img src='images/testimonials/france_006.JPG' width='134' height='100' alt='Click to enlarge' style='margin: 0 4px;' /></a>

 

Once you click on the image it should change the innerHTML of this

<div id="tp2" class="testiPicture"><img src='images/testimonials/france_006.JPG' width='400' height='300' alt='Before/After Picture' /></div>

 

Im passing in the ID of the div and file name to the JS as there is a few different small galleries on page, all PHP generated and works fine until the onpage image swap is called using my JS script which as normal when i write JS it didn't work :D.

 

Any body have incite to why.

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/151264-solved-image-swap-using-innerhtml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.