user3304709
user3304709

Reputation:

showing images on mouseover of another images using javascript

<script type="text/javascript">
function bigpic()
{
document.getElementById('img2').src="<?php echo '../images/$img2';?>";  
}

 <img name="img1" src="<?php echo "../images/$img1";?>" width="100px" height="100px"    onmouseover="bigpic()"/>
 <img name="img2" src="" width="32" height="32" alt="" id="img2"/>

$img1 and $img2 are fetched from mysql database and fetching is working well. But $img2 is not displayed while mouseover on img1. This is what i have tried. What is wrong here.

Upvotes: 0

Views: 81

Answers (2)

Chetan Gawai
Chetan Gawai

Reputation: 2401

Your code worked fine with me using static images. Try this

<script type="text/javascript">
function bigpic()
{
document.getElementById('img2').src="<?php echo '../images/'.$img2 ;?>";  
}
</script>

<img name="img1" src="<?php echo "../images/" . $img1;?>" width="100px" height="100px"    onmouseover="bigpic()"/>
 <img name="img2" src="" width="32" height="32" alt="" id="img2"/>

Upvotes: 0

SajithNair
SajithNair

Reputation: 3867

Change this

document.getElementById('img2').src="<?php echo '../images/$img2';?>"; 

To this

document.getElementById('img2').src="<?php echo "../images/$img2";?>"; 

Reason, single quoted strings does not evaluate a variable.

Upvotes: 3

Related Questions