|
-
Nov 17th, 2005, 02:43 AM
#1
Thread Starter
Lively Member
Why doesn't this javascript code run ?
I want when the user points to a picture link, the picture will become another one. But the following code will always have erros: document[...] is null or is not an object. What's the problem ?
<script language="JavaScript" type="text/javascript">
<!--
productoff = new Image;
productoff.src = "./img/product.gif";
productover = new Image;
productover.src = "./img/news.gif";
function replaceImg(oldImg,newImg){
document[oldImg].src = eval(newImg + ".src");
}
//-->
</script>
<td><a href="./product.html" onMouseOver = "replaceImg('productoff','productover')" onMouseOut = "replaceImg('productoff','productover')" ><img src = "./img/product.gif" ></a></td>
-
Nov 17th, 2005, 09:55 AM
#2
Re: Why doesn't this javascript code run ?
Give the image tag a name attribute. That's what you're supposed to be passing.
PHP Code:
function replaceImg(imgname,newImg){
document[imgname].src = eval(newImg + ".src");
}
When calling it,
HTML Code:
<a href="./product.html" onMouseOver="replaceImg('prodimg', 'productover');"><img src="./img/product.gif" name="prodimg"></a>
-
Nov 17th, 2005, 07:04 PM
#3
Thread Starter
Lively Member
Re: Why doesn't this javascript code run ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|