Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Function ChangeImage can't work in Firefox

Status
Not open for further replies.

jepe666

Programmer
Apr 17, 2008
36
ID
I have problem in firefox,my code works in IE...
here's my code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">

function changeImage(filename)
{
mainimage.src =filename;
}

</script>
</head>
<body>
<a href="javascript:changeImage('includes/images/fotoproduk/CRJ624.jpg')"><img src="includes/images/fotoproduk/thCRJ624.png"></a></td><td align="center" width="40">
</body>
</html>

please for solution..

thanks for your advance
 
How does this possibly work in IE??

Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">

function changeImage(filename)
{
  [red]mainimage[/red].src =filename;
  [fuchsia]// where is there anything called "mainimage"??[/fuchsia]
}

</script>
</head>
<body>
<a href="javascript:changeImage('includes/images/fotoproduk/CRJ624.jpg')"><img src="includes/images/fotoproduk/thCRJ624.png"></a></td><td align="center" width="40">
</body>
</html>

There is no such "mainimage" in your html code. Did you mean i.e. <img name="mainimage"> there?

The proper, correct, standards-compliant, and most of all, cross-browser, method of doing such a thing is as follows:

1) Give your image an "id" attribute

Code:
<img src="whatever.gif" [blue]id="mainimage"[/blue] alt="whatever">

2) Use document.getElementById()

Code:
document.getElementById("[blue]mainimage[/blue]").src = "newpicture.gif";

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
sorry i forgot to declare mainimage
here's the code :
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">

function changeImage(filename)
{
mainimage.src =filename;
// where is there anything called "mainimage"??
}

</script>
</head>
<body>
<IMG class=image1 height=506 align="right" name="mainimage" src="includes/images/harmond/CRJ-624.jpg">

<a href="javascript:changeImage('includes/images/fotoproduk/CRJ624.jpg')"><img src="includes/images/fotoproduk/thCRJ624.png"></a></td><td align="center" width="40">
</body>
</html>
 
to kirsle
thank alot you save my day..
thanks your solution successfull...
 
Hi

Here on Tek-Tips we used to thank for the received help by giving stars. Please click the

* [navy]Thank Kirsle
for this valuable post![/navy]


at the bottom of Kirsle's post. That way you both show your gratitude and indicate this thread as helpful.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top