472,985 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 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 3142
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.