Sorry, that won't work reliably cross-browser. Try with this correction.
Main Topics
Browse All TopicsIs it possible to have the reference from a link determine what the source of an image will be?
I currently have a page with 30 links. The HTML follows this methodology:
<li><a href="#0001">Link 1</a></li>
<li><a href="#0002">Link 2</a></li>
...
<li><a href="#0030">Link 30</a></li>
With that, I'm wanting to change the source of the image. For instance, if someone clicks on Link 1, I want the image URL to be ../image0001.jpg. Link 2 being ../image0002.jpg etc.
Any ideas as to how I would do this with javascript?
Thanks in advance.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Things have to be this way because it's a limitation of the iUI library for iPhone web application development. To further explain things I am developing a web application that displays the feed from traffic cameras. Because there are over 100 of them, I figured it would be a lot easier have one page (or div tag in this case) handle the camera view and other information, and that information could come from the link bringing it there.
I've attached a code snippet to give you the gist of things. Let me know if it helps, and if you'd recommend a different solution because of it.
Thanks for the help thus far though. :-)
I'm not entirely clear on what the navigation scheme is here. You want the user to click a link, and be redirected to a new page? Or you want them to click a link and have it update the current page accordingly? Based on the code you provided, I think you mean the latter. You will run into a small problem of differentiating between links that should update the image and those that don't. I would just drop a class onto the ones that do.
Same base code as before, but here's one with some added in stuff to update the local page based on the href value. Note that you MUST return false at the end of the handler function to avoid redirecting the page.
Uh oh, I think I've made this more complicated than it needed to be. With that said, I'm EXTREMELY appreciative for your help so far. To clarify, here's why everything is structured the way it is.
The part of the iPhone UI that I'm emulating is when it generates lists and and a selection is made, it "slides" to the next set of options. You can see the app I'm working on at http://mrgravy.com/iphone.
With that said, the old version of this app had each camera with it's own "panel," or div element. For the sake of better coding, I want to use one div element, called "cameraView" This cameraView panel contains the most current image from the webcam, and it's mile marker location. I figured that javascript would allow me to write a function that can alter the image URL of the image and text label with the mile marker info, depending on which camera in the list is clicked. It's just I have no clue how to do it for the time being...
...so in other words, ALL camera links must point to "#cameraView" I've tried <a href="#cameraView" onClick='document.getEleme
Mother of God. I'm starting to lose my mind now. ANY help here would save the day.
What I've attached below is the function I created to change the URL of the image that will display the webcam. In theory it makes sense. However, when testing it in Firefox and on the iPhone, nothing happens when the camera link is clicked. However, in IE8, it works fine. That's besides the point though, because it needs to work on the iPhone's Safari.
In order to get the iPhone UI goodness, I'm having to use the iUI library, which has it's own javascript as well. It's attached as well, and it's making me think that there's a conflict somewhere. A conflict that one of you javascript guru's could pick up on in less than a few minutes.
So please, any help to get me going again will be GREATLY appreciated!
Thanks in advance!
It's an iPhone UI conflict. You're linking to #displayCamera like you're supposed to, but you've then id'ed the div as "#displayCamera". It should be "displayCamera" (w/out the # first). I copied the code of your test site, made a couple of changes to insert what you have here, and have am posting a complete version. Seems to work fine to me.
Business Accounts
Answer for Membership
by: mkosbiePosted on 2009-05-04 at 03:32:07ID: 24293757
Why do you want to make the links this way? Why not just put the actual full image path in the links?
Anyways, to answer the question, attach a click handler to all the <a> tags on the page, then in the function that processes it, manually handle the redirect. Something like this maybe.
Select allOpen in new window