/    Sign up×
Community /Pin to ProfileBookmark

Need help with usemap

Hi! I want to display an image (wich is actually a image map) that i’m trying to get it to be replaced by another image (another image map). The way i want it to work is: have the previous image map replaced by another one, depending on the speficic area you clicked.

So far I’ve managed to acomplish this for the first image replacement, but then the second image map is not working. There is also another problem, this works for IE under Windows but not for FF under Linux.

Here’s the code:
(…)
function change_pic(area,image_name,image_map)
{
document.getElementById(area).src=image_name;
document.getElementById(area).useMap=image_map;
}
(…)
<img id=”body_img” class=”body_map” src=”img/body2.jpg” usemap=”#full_body” border=”0″>
<map id=”full_body” name=”full_body”>
<a href=”#” onclick=”change_pic(‘body_img’,’img/head.jpg’,’#full_head’)”>
<area shape=”rect” coords=”136,7,168,46″ alt=”Head”>
</a>
<a href=”#” onclick=”change_pic(‘body_img’,’img/body_torso_head.jpg’,’#upper_torso’)”>
<area shape=”rect” coords=”115,46,180,170″ alt=”Torso”>
</a>
</map>
<map id=”full_head” name=”full_head”>
<a href=”#” onclick=”change_pic(‘body_img’,’img/eyeball.jpg’,’#full_eye”)”><area shape=”circle” coords=”135,198,51″ alt=”Eyeball”></a>
</map>
<map id=”upper_torso” name=”upper_torso”>
</map>
<br>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliNov 04.2007 — <i>
</i> &lt;map id="full_body" name="full_body"&gt;
&lt;a href="#" onclick="change_pic('body_img','img/head.jpg','#full_head')"&gt;
&lt;area shape="rect" coords="136,7,168,46" alt="Head"&gt;
&lt;/a&gt;
&lt;a href="#" onclick="change_pic('body_img','img/body_torso_head.jpg','#upper_torso')"&gt;
&lt;area shape="rect" coords="115,46,180,170" alt="Torso"&gt;
&lt;/a&gt;
&lt;/map&gt;
[/quote]
<area> elements act as links and therefore should not need to be enclosed within links. Try removing the links and transfer the href and onclick parameters into the area elements.
×

Success!

Help @Zeus-electro 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.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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