/    Sign up×
Community /Pin to ProfileBookmark

Javascripting Firefox

I am using the following code to display images for a website, seems to work very nicely in Safari, images render a little slow in ie however in firefox the main image displays but will not change image when I click on the next image? Any suggestions? Thanks in advance.

<HEAD>

<SCRIPT LANGUAGE=”JavaScript”>

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

</script>

</HEAD>

<BODY>

<p>
<a href=”javascript:changeImage(‘image-viewer/image1.jpg’)”>Image 1</a>
<a href=”javascript:changeImage(‘image-viewer/image2.jpg’)”>Image 2</a>
<a href=”javascript:changeImage(‘image-viewer/image3.jpg’)”>Image 3</a>
<a href=”javascript:changeImage(‘image-viewer/image4.jpg’)”>Image 4</a>
</p>
<p>
<img name=”mainimage” src=”image-viewer/blank.jpg”></p>

<p><center>
<font face=”arial, helvetica” size”-2″>Free JavaScripts provided<br>
by <a href=”http://javascriptsource.com”>The JavaScript Source</a></font>
</center><p>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERApr 15.2011 — That's a pretty old version ... :eek:

If that's what you want to do, try this...
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;SCRIPT type="text/javascript"&gt; &lt;!-- archaic format: LANGUAGE="JavaScript" --&gt;

var baseURL = 'image-viewer/';
var imgList = ['','image1.jpg','image2.jpg','image3.jpg','image4.jpg'];
function changeImage(ptr) {
document.getElementById('mainimage').src = baseURL+imgList[ptr];
document.getElementById('mainimage').alt = imgList[ptr];
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;p&gt;
&lt;a href="#" onclick="changeImage(1)"&gt;Image 1&lt;/a&gt;
&lt;a href="#" onclick="changeImage(2)"&gt;Image 2&lt;/a&gt;
&lt;a href="#" onclick="changeImage(3)"&gt;Image 3&lt;/a&gt;
&lt;a href="#" onclick="changeImage(4)"&gt;Image 4&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img id="mainimage" src="image-viewer/blank.jpg" alt="blank.jpg"&gt;&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;


BTW: You should enclose your script between [ code] and [ /code] tags (without the spaces)

to make it easier to read, copy, test your programs.
×

Success!

Help @felix71 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...