By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

swap image and link change help (javascript)

P: n/a
Hi,

Ok so on a given page I have 4 text links:

see it in black
see it in blue
see it in red
see it in green

using the standard swap image behavior, clicking on one of the above links
changes a displayed image to:

black.jpg
blue.jpg
red.jpg
green.jpg

So far no problem.

Now, I also have a set of images called:

blackL.jpg
blueL.jpg
redL.jpg
greenL.jpg

These are larger versions of the 4 images being swapped.

What I am trying to do is have a text link that says "Click to enlarge"
underneath the image on the page that when clicked will popup a window with
the corresponding "L" (large) image (I already know how to launch a popup).

So, someone clicks the text link for "see it in black", the default image
on the page swaps to "black.jpg" and the text link underneath would launch
a popup containing "blackL.jpg"

Same for see it in blue, see it in red, see it in green

I can't figure out how to make the "Click to enlarge" text link change the
popup it will call whenever someone clicks the corresponding text link
elsewhere on the page.

IOW, clicking "see it in black" makes this text link on the page:

<a href="javascript:;" Onclick="popupwindow(blackL.jpg)"Click to enlarge
</a>

clicking "see it in red" makes this:

<a href="javascript:;" Onclick="popupwindow(redL.jpg)"Click to enlarge</a>

That's pseudocode shorthand of course for an actual popup window behavior.

Did this make sense? Can someone help me?

I'm thinking I need to use an array somehow?
Mar 28 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
RE**************@cox.net (Lee) wrote in <e0*********@drn.newsguy.com>:
Karl said:
Did this make sense? Can someone help me?

I'm thinking I need to use an array somehow?


Did the instructor hint that you should use an array?
That's not how I would do it.

No that was just a guess,

Can you tell me what you think I should do?
Mar 28 '06 #2

P: n/a
Anyone? Please, I'm out of ideas on how to do this after 8 hours of
googling. Nothing works right.
Karl said:
Did this make sense? Can someone help me?

I'm thinking I need to use an array somehow?


Did the instructor hint that you should use an array?
That's not how I would do it.

No that was just a guess,

Can you tell me what you think I should do?


Mar 29 '06 #3

P: n/a
Karl said on 29/03/2006 6:33 AM AEST:
Hi,

Ok so on a given page I have 4 text links:

see it in black
see it in blue
see it in red
see it in green

using the standard swap image behavior, clicking on one of the above links
changes a displayed image to:

black.jpg
blue.jpg
red.jpg
green.jpg

So far no problem.

Now, I also have a set of images called:

blackL.jpg
blueL.jpg
redL.jpg
greenL.jpg

These are larger versions of the 4 images being swapped.

What I am trying to do is have a text link that says "Click to enlarge"
underneath the image on the page that when clicked will popup a window with
the corresponding "L" (large) image (I already know how to launch a popup).

So, someone clicks the text link for "see it in black", the default image
on the page swaps to "black.jpg" and the text link underneath would launch
a popup containing "blackL.jpg"

Same for see it in blue, see it in red, see it in green

I can't figure out how to make the "Click to enlarge" text link change the
popup it will call whenever someone clicks the corresponding text link
elsewhere on the page.

IOW, clicking "see it in black" makes this text link on the page:

<a href="javascript:;" Onclick="popupwindow(blackL.jpg)"Click to enlarge
</a>
The href should point to the actual image, not junk. But why use an A
element at all? You want to work with an image:

<img src="black.jpg" onclick="popupwindow(this);" ... >Click to enlarge
In popupwindow:

function popupwindow(img)
{
var imgSrc = img.src.replace(/\.jpg/,'L.jpg');
...
}

[...]
I'm thinking I need to use an array somehow?


If you like to complicate things, sure.
--
Rob
Mar 29 '06 #4

P: n/a
rg***@iinet.net.au (RobG) wrote in
<oA******************@news.optus.net.au>:
Karl said on 29/03/2006 6:33 AM AEST:
Hi,

Ok so on a given page I have 4 text links:

see it in black
see it in blue
see it in red
see it in green

using the standard swap image behavior, clicking on one of the above
links changes a displayed image to:

black.jpg
blue.jpg
red.jpg
green.jpg

So far no problem.

Now, I also have a set of images called:

blackL.jpg
blueL.jpg
redL.jpg
greenL.jpg

These are larger versions of the 4 images being swapped.

What I am trying to do is have a text link that says "Click to
enlarge" underneath the image on the page that when clicked will popup
a window with the corresponding "L" (large) image (I already know how
to launch a popup).

So, someone clicks the text link for "see it in black", the default
image on the page swaps to "black.jpg" and the text link underneath
would launch a popup containing "blackL.jpg"

Same for see it in blue, see it in red, see it in green

I can't figure out how to make the "Click to enlarge" text link change
the popup it will call whenever someone clicks the corresponding text
link elsewhere on the page.

IOW, clicking "see it in black" makes this text link on the page:

<a href="javascript:;" Onclick="popupwindow(blackL.jpg)"Click to
<enlarge /a>
The href should point to the actual image, not junk. But why use an A
element at all? You want to work with an image:

No. I am not trying to make the image itself a link. I need the link that
opens the popup window to be a text link. Maybe I didn't explain that
part? I thought I did.

<img src="black.jpg" onclick="popupwindow(this);" ... >Click to enlarge
In popupwindow:

function popupwindow(img)
{
var imgSrc = img.src.replace(/\.jpg/,'L.jpg');
...
}

[...]


This makes no sense to me. I can't believe in all my searching I havn't
found a clear answer to what seems like a common thing to want to do...

Mar 29 '06 #5

P: n/a
Karl said on 29/03/2006 4:03 PM AEST:
rg***@iinet.net.au (RobG) wrote in
<oA******************@news.optus.net.au>:

Karl said on 29/03/2006 6:33 AM AEST: [...]
<a href="javascript:;" Onclick="popupwindow(blackL.jpg)"Click to
<enlarge /a>


The href should point to the actual image, not junk. But why use an A
element at all? You want to work with an image:


No. I am not trying to make the image itself a link. I need the link that
opens the popup window to be a text link. Maybe I didn't explain that
part? I thought I did.


The general idea is to only suggest clicking on something if something
useful will happen. Links that are dependent on script should only be
made available by script. An A element provides the opportunity to
deliver functionality without script.

If an A element is used, the href should point to something useful.
Putting an empty script statement in there is no better than an empty
string. Why not have the href at least point to the default image so
that if JavaScript isn't available at least they get to see something.
And since they don't have scripting, they can't see the alternative
thumbnails anyway.

Oh, and you shouldn't only consider fail-over if scripting is
disabled/not supported, you should also consider it where the features
of your script are not fully supported.

e.g.

<a href="blackL.jpg" onclick="return popupwindow(...);"> ... </a>
So if popupwindow() detects some feature that isn't supported, it tidies
up and returns true so the link is followed. Otherwise it does its
thing (pops up the required image) and returns false so the link
navigation is canceled.

<img src="black.jpg" onclick="popupwindow(this);" ... >Click to enlarge
In popupwindow:

function popupwindow(img)
{
var imgSrc = img.src.replace(/\.jpg/,'L.jpg');
...
}

[...]

This makes no sense to me. I can't believe in all my searching I havn't
found a clear answer to what seems like a common thing to want to do...


A better version is:

var imgSrc = img.src.replace(/\.jpg$/,'L.jpg');
to match .jpg only at the end of the string. Now you can have the
string '.jpg' elsewhere in the path, e.g.

/images/all.jpgs/black.jpg
or similar.


--
Rob
Mar 29 '06 #6

P: n/a
Maybe this will make more sense with an example:

http://www.rei.com/product/47985505.htm

This is almost EXACTLY what I am trying to do. Click one of the available
colors thumbnails (sprout Steel). Then Click for larger View below the
swapped image. I want exactly this effect except using text links instead
of little thumbnails and the larger view photo appears in a popup instead
of in the same window.

I'm looking through their code but it's mostly going over my head (as did
your explanations below).

The general idea is to only suggest clicking on something if something
useful will happen. Links that are dependent on script should only be
made available by script. An A element provides the opportunity to
deliver functionality without script.

If an A element is used, the href should point to something useful.
Putting an empty script statement in there is no better than an empty
string. Why not have the href at least point to the default image so
that if JavaScript isn't available at least they get to see something.
And since they don't have scripting, they can't see the alternative
thumbnails anyway.

Oh, and you shouldn't only consider fail-over if scripting is
disabled/not supported, you should also consider it where the features
of your script are not fully supported.

e.g.

<a href="blackL.jpg" onclick="return popupwindow(...);"> ... </a>
So if popupwindow() detects some feature that isn't supported, it tidies
up and returns true so the link is followed. Otherwise it does its
thing (pops up the required image) and returns false so the link
navigation is canceled.

<img src="black.jpg" onclick="popupwindow(this);" ... >Click to
<enlarge
In popupwindow:

function popupwindow(img)
{
var imgSrc = img.src.replace(/\.jpg/,'L.jpg');
...
}

[...]

This makes no sense to me. I can't believe in all my searching I
havn't found a clear answer to what seems like a common thing to want
to do...


A better version is:

var imgSrc = img.src.replace(/\.jpg$/,'L.jpg');
to match .jpg only at the end of the string. Now you can have the
string '.jpg' elsewhere in the path, e.g.

/images/all.jpgs/black.jpg
or similar.


Mar 29 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.