I don't want to make second post with the same title although difference in methods.So you can also use..
function alter_image(image_src,image_name)
{
document.getElementById(image_name).src=image_src;
}
<a href="javascript:void(0);" onmouseover="alter_image('image/photo2.jpeg','image1')" onmouseout="alter_image('image/photo1.jpeg','image1')" rel="nofollow">
<img src="image/photo1.jpeg" id="image1" border="0">
</a>
Try this it also work the same.
only with slight changes as id and use of getElementById.
