/    Sign up×
Community /Pin to ProfileBookmark

onclick picture won’t show

I’ve created a page that has three hyperlinks, with the intention that when the link is clicked, an image will swap. Pretty rudimentary javascript, i’d imagine.

Problem is, that sometimes (?) the image doesn’t appear, especially on a ‘fresh’ computer. You can however get it to show by right-clicking the image and selecting ‘Show Picture’. Then it works. Not a very desireable requirement. Any ideas on how to correct it?

Here’s my page- [URL]http://www.off-road.com/atv/kidskorner/suspension4.html[/URL]

And the hyperlink code (javascript is actually not two words)-

[CODE]
<a href=”javascript:” onclick=”document.MyImage.src=’images/suspen2.gif’;”>
<b><u>here</u></b></a>to show table, or
<a href=”javascript:” onclick=”document.MyImage.src=’images/suspen1.gif’;”>
<b><u>here</u></b></a> to show gragh,<br>or
<a href=”javascript:” onclick=”document.MyImage.src=’images/PC160001_small.JPG’;”>
<b><u>here</u></b></a>to show the tires </p>[/CODE]

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@CharlesDec 28.2004 — This would be a great deal easier and work a great deal better if you just used an [url=http://www.w3.org/TR/html401/present/frames.html#edef-IFRAME]IFRAME[/url].
Copy linkTweet thisAlerts:
@i-ZappauthorDec 28.2004 — geese. what took you so long! :rolleyes:

i'll take a look, but would like to know why the original didnt work.
Copy linkTweet thisAlerts:
@CharlesDec 28.2004 — [i]Originally posted by i-Zapp [/i]

[B]geese. what took you so long! :rolleyes:

i'll take a look, but would like to know why the original didnt work. [/B]
[/QUOTE]
What you have shouldn't work at all. You're asking for the image to be loaded just before the whole page is swapped out.
Copy linkTweet thisAlerts:
@i-ZappauthorDec 28.2004 — regarding the IFRAME, do i essentially just replace the <a> tags with the <IFRAME> tags?

the validator is cool. re the images, it only tells me that the ALT parameter was missing. i can't imagine that would cause the problem.

since this is the javascript forum, i thought there'd be some "duh!" wisdom about why simple script doesnt work.
Copy linkTweet thisAlerts:
@i-ZappauthorDec 28.2004 — What you have shouldn't work at all.[/QUOTE]

did you try my page? what happens when you 'show picture'?

any ideas on how to FIX it? i suppose i'm game for abandoning my original approach, but would like to really learn why it didnt work or how to make it work.
Copy linkTweet thisAlerts:
@CharlesDec 28.2004 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

<title>Example</title>

<base href="http://www.off-road.com/atv/kidskorner/suspension4.html">

</head>

<body>

<iframe name="frame" height="263" width="330"></iframe>

<ul>

<li><a href="images/suspen2.gif" target="frame">Table</a>,</li>

<li><a href="images/suspen1.gif" target="frame">TGraph</a>,</li>

<li><a href="images/PC160001_small.JPG" target="frame">Tyres</a>.</li>

</body>

</html>[/font]

Yours is just too messed up to explain.
Copy linkTweet thisAlerts:
@KorDec 29.2004 — I got you Charles! But what about the DTD strict? Your target woun't work, as you just said recently in another thread...

? ? :p
Copy linkTweet thisAlerts:
@Warren86Dec 29.2004 — i-Zapp:

Using your table and changing name="MyImage" to id="MyImage":

<HTML>

<Head>

<Script Language=JavaScript>

var tableImg = "suspen2.gif"
var graphImg = "suspen1.gif"
var tiresImg = "PC160001_small.JPG"
var imgPath = "images/"

function swapImg(currImg){

document.getElementById('MyImage').src = imgPath+currImg;
}


</Script>

</Head>

<Body>

<table border="0" width="40%" align="right" bgcolor="#000000">

<tr>

<td width="100%" align="center">

<p><img border="0" src="images/suspen1.gif" id="MyImage" width="361" height="263"></p>

</td>

</tr>

<tr>

<td width="100%">

<p align="center"><font size="1"><font color="#FFFFFF" face="Arial">click

</font>

<a href=javascript:swapImg(tableImg)><font color="#FFFFFF" face="Arial" size="2"><b><u>here</u></b></font></a> <font color="#FFFFFF" face="Arial" size="2"> to show table, or

</font>

<a href=javascript:swapImg(graphImg)><font color="#FFFFFF" face="Arial" size="2"><b><u>here</u></b></font></a> <font color="#FFFFFF" face="Arial" size="2"> to show gragh,&nbsp;<br>

or </font>

<a href=javascript:swapImg(tiresImg)><font color="#FFFFFF" face="Arial" size="2"><b><u>here</u></b></font></a> <font color="#FFFFFF" face="Arial" size="2"> to show

the tires (shown in order)</font></font></p>

</td>

</tr>

</table>

</Body>

</HTML>
Copy linkTweet thisAlerts:
@i-ZappauthorDec 29.2004 — thanks to all.

admittedly, i am no js programmer. it's just something that helps me do my job more effectively.

i adopted Warren's approach, only because it was a slam-dunk, ready to go solution. thanks bud!

i also tried Chas solution, which although worked, required additioanl manipulation to get it look the way i wanted, which i lack the experience and time to figure out. thanks anyway. when i have some time, maybe i'll give it a go.
Copy linkTweet thisAlerts:
@Warren86Dec 29.2004 — You're welcome. Good luck with your project.
Copy linkTweet thisAlerts:
@CharlesDec 29.2004 — [i]Originally posted by Kor [/i]

[B]I got you Charles! But what about the DTD strict? Your target woun't work, as you just said recently in another thread...



? ? :p [/B]
[/QUOTE]
Please note, I've used the transitional DTD. [i]From the HTML 4.01 Transitional DTD:[/i]

[b][font=monospace]This is the HTML 4.01 Transitional DTD, which includes presentation attributes and elements that W3C expects to phase out as support for style sheets matures. Authors should use the Strict DTD when possible, but may use the Transitional DTD when support for presentation attribute and elements is required.[/font][/b]

[i] http://www.w3.org/TR/html401/sgml/loosedtd.html [/i][/quote]
This happens to be the one case where there is no real alternative to using the "target" attribute and so is the last place where the transitional DTD is appropriate.
Copy linkTweet thisAlerts:
@KorJan 03.2005 — I know Chrales... I was just teasing u...?
×

Success!

Help @i-Zapp 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 6.1,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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