Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1995
  • Last Modified:

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!
0
junior2e
Asked:
junior2e
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now