/    Sign up×
Community /Pin to ProfileBookmark

Using Javascript var as input to HTML img argument

Hi!

I’m a newbie to Javascript and I’m hoping someone here can help me with my programming problem!

I have an html file that contains an IMG tag that has a “USEMAP” argument. I would like to be able to use a variable for the USEMAP. Here’s an example:

I have two maps:
<map name=map1>
<area ….>
<area ….>
</map>
<map name=map2>
<area ….>
<area ….>
</map>

Later in the html I have this img tag

<img src=”filename.jpg” name=”image” usemap=”<here is where I’d like to use a variable”>

Still later in the html

<a href=”file.html” onMouseover=”document.images[‘image’].src=’newimage1.jpg’; return true;”>Link 1</a>
<a href=”file2.html”
onMouseover=”document.images[‘image’].src=’newimage2.jpg’; return true;”>Link 2</a>

So that when the user puts his/her mouse over “Link1,” the image formerly known as ‘filename.jpg’ is replaced by ‘newimage1.jpg’ and would use map named ‘map1’.

If the user then places the mouse over “Link2,” the image would change and a new map would be used.

I’m stumped!! Any and all help that you can provide would be GREATLY appreciated!!!

Thanks!

Kay

to post a comment
HTML

7 Comments(s)

Copy linkTweet thisAlerts:
@khakiApr 08.2003 — Hi Kay...

Just when I think that I understand what you mean... it falls right back out of my head :eek: .

Can you provide a link (preferably) or some more complete source code and try to explain it a little differently?

I think I know what you mean... but not really. But I have something that uses ImageMaps and Javascript varibles somewhere in my archives... so maybe I can see if it applies to your particular need.

I'll look for it later. In the meantime, provide a link ? or more source code ? and I'll try to figure out if I can understand it any better.

? k
Copy linkTweet thisAlerts:
@khakiApr 08.2003 — hey Kay...

you double-posted this

http://forums.webdeveloper.com/showthread.php?s=&postid=37051#post37051

This probably belongs in the Javascript forum, but you are going to confuse everybody if you double-post.

i'll keep answering here (unless a Moderator moves it), but I will check the other post in case you have some info there that solves or explains things better.

(you really shouldn't double-post. It can have a back-firing effect from some of the people who want to help you. ? )
Copy linkTweet thisAlerts:
@khakiApr 08.2003 — oh...

I think I understand.

Yeah... I think that can be done using a mouse-over array (or whatever it's called :rolleyes: ).

I have that somewhere... let me find it

(i can't write this stuff from scratch like a lot of these guys... so give me a sec)

:rolleyes: k
Copy linkTweet thisAlerts:
@KayC4authorApr 09.2003 — Hi Khaki,

Thanks so much for responding. I apologize for the double posts but I wasn't sure if someone who has done this using HTML might not venture to the Javascript board. I thought having the post in both places might up my chances of getting an answer. Sorry for the confusion!! I've posted this problem at several other programming boards and I haven't been very lucky at finding a solution, so I really hope that you can help.

What I have is a page that displays an image on the page load. I want to change that image when the user puts their mouse over a link and I want to make that new image and imagemap.

I hope this better explains what I'm looking for. What I need is to be able to pass a variable to the "usemap" argument in the IMG tag.

Thanks so much for taking the time to help me figure out this problem!

Kay
Copy linkTweet thisAlerts:
@khakiApr 09.2003 — Hi Kay...

Unfortunately I haven't been able to get this to work either.

There are a couple of problems that make this one so tough.

Firts of all... it's easy to get the links/mouseovers to display the different imagemaps to come up.

But the hard part is getting the imagemap's links/coordinates to work on the imagemap that is activated.

Maybe someone knows how to incorporate the [B]usemap[/B] part into the mouseover function... but I couldn't get it to go (although... I'm far from a javascript expert. V--E--R--Y----far!).

The other problem is that this solution (if solved!) carries an additional problem for javascript disabled browers (if that matters to you in your particular application).

So even if the imagemap is able to function properly as an imagemap... javascript disabled browsers will not have access to that.

So... if you are on an intranet (javascript enabled) that won't matter to you. If you are putting this on the internet, it will not work for the physically disabled who cannot use a mouse and/or who must have javascript disabled in order to surf.

The rest of the people who disable javascript by their own preference will need to decide for themselves if they wish to enable javascript in order to use this method of navigation.

Sorry for the rant on that... but this method is a bit gimmicky (creatively cool though! ? ), so you should consider all factors if you choose to implement this (if it's even possible! :eek: ).

and if I may ('cause i've rambled a bit already :rolleyes: )...

I would really like to learn how to incorporate the [B]usemap[/B] part into the mouseover feature.

Maybe this can all be done by having the entire page written with [B]document.write(...)[/B] throughout... but I really don't know :rolleyes: ).

I'll play with this a bit more from time to time... but I'm stuck!.

Hopefully someone else has some ideas ? .

Creative thinking though, Kay!

(if it works! lol)

good luck...

? k
Copy linkTweet thisAlerts:
@KayC4authorApr 09.2003 — Hi Khaki,

Thanks for the rant! LOL!! I've thought through the javascript disabled browsers and I will provide an alternate "click" page that will provide them with the links that others who use javascript will be able to see, but I appreciate you pointing this out to me.

I REALLY wish you had a solution for this! LOL! I've tried SO many things and nothing works, I was hoping this board would have the expertise that I obviously do not possess. Thanks for sympathizing with my problem.

Kay
Copy linkTweet thisAlerts:
@khakiApr 09.2003 — Hi Kay...

I'm really stumped.

And... since this really is a Javascript question... I created a new ([B][I]another[/B]... shhhh[/I]) thread over there to specifically address incorporating the [B]usemap[/B] part into the mouseover/out script.

That thread is here:

http://forums.webdeveloper.com/showthread.php?s=&threadid=7497

(i hope you don't mind that I did this... but I've already burned so many braincells on this that I feel somewhat attached to finding the solution).

So... lets see what they got to offer over there

? k
×

Success!

Help @KayC4 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.5,
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,
)...