onClick - change href

I have a dynamic list of thumbnails, and one cooresponding "medium" sized image that changes onClick... I also need to be able to allow the user to click on this medium sized image to view the "large" image.

My JS function is as -
function showMedium(imageName) {
     document.bigImage.src = imageName;
}

This changes the medium size image, but I have a "a href" around the medium sized image that also needs to change.

<a href='???' target='new'><img name='bigImage' width='400' height='300' src='images/homes/medium/" & house_ID & ".jpg' border='0'></a>

Can I change the "href" value onClick - inside the above function?

Thanks!
junior2eAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AArnieCommented:
Sure you can,

Just add an 'id' to the Href...

<A Href="link" id="Href1" Name="Href1">links</A>

then in code...

function changeHref(){
  document.all("Href1").href="newlink"
}

AArnie.
0
AArnieCommented:
Dont forget changeHref() needs to be called from an event some where...

AArnie.
0
gator4lifeCommented:
You can do this a couple of different ways:

* NOTE: These solutions require a DOM (Document Object Model) compatible browser (e.g. IE5+, NS6+).

(1) Add id="myAnchor" to the <a> tag. Then, change your showMedium() function to this:

function showMedium(imageName, imageHref) {

     with (document) {

          bigImage.src = imageName;
          getElementById('myAnchor').href = imageHref;
     }
}

(2) Don't add anything to the <a> tag. Then, change your showMedium() function to this:

function showMedium(imageName, imageHref) {

     with (document.bigImage) {

          src = imageName;
          parentNode.href = imageHref;
     }
}

Hope this helps you out.

gator4life
(chomp, chomp)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

gator4lifeCommented:
AArnie's solution will only work in Internet Explorer 4.0+, since the "all" collection is a Microsoft proprietary extension to the "document" object.  It is not recognized as a standard, and it will not work in any other browsers.  The DOM is an open standard that all modern browsers must conform to.

gator4life
(chomp, chomp)
0
junior2eAuthor Commented:
awesome, thanks for the help!
0
jaysolomonCommented:
*******************************************************
******PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER******
*******************************************************
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area:
RECOMMENDATION:

 - [Points to gator4life Grade A]

Please leave any comments here within the next seven days.
*******************************************************
******PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER******
*******************************************************

jAy
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.