473,396 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

swap image and link change help (javascript)

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
6 3167
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wlad | last post by:
Hi, Does anybody knows how to make the browser lauch an external image editor (i.e. Photoshop) when the user clicks on a link like this : <a href=...
4
by: zborisau | last post by:
Hey good people, I've been given a problem to solve recently - and stuck with the solution for a good 4 days already. i have a link which leads to popup window. the purpose of that popup...
2
by: Madame Blablavatsky | last post by:
hello, i have an image that is also a link: <a href="javascript:opmaak('bold','')"><img src='bold_uit.gif name='uit'></a> when the image/link is clicked it triggers a javascript that...
5
by: Mel | last post by:
i like to place an image link on my page that stays up for 2 seconds and user can interact with. if no interaction in 2 seconds the image and the link should disapear please help
2
by: Barkster | last post by:
I have a image that I want to click and when clicked that image will be swapped and then show a hidden div. When another image like it is clicked it will swap image and hide that text and so on. ...
6
by: fredo | last post by:
A few days ago, Jim answered (THANK YOU, Jim) my question about how to make an image pop up when an image link is hovered. That discussion is here: ...
4
by: lemat | last post by:
Hi, I use a radio button form in which users can select a color by clicking on a image. I would like this image to change to another one when it's chosen. (image with a "Chosen" Stamp in the...
3
by: PEJO | last post by:
I'm not much of a JS programmer so I used the the standard Macromedia swap image function for a disjointed rollover..which works fine.. no problem swapping the image with that code.... but when...
3
by: zion | last post by:
Hello, How can I return image link with webservice that I could see it in web page? The image is on my hard disk and <img src="c:\pictures\test.jpg" /does not work. If I use <img src=http://My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.