Solved

Can you swap images and swap href properties associated with the images onclick?

Posted on 2003-10-26
5
300 Views
Last Modified: 2011-09-20
Can you swap images and the href properties associated with both images onclick? For example based on the script below.
I am intending for the links to target either pop-ups or pages in other frames and function like a toggle switch.

<script language="JavaScript"><!--
function flip(name,src) {
    if (document.images)
        document.images[name].src = src;
}
//--></script>

<a href="#" onClick="flip('image1','image1a.gif');return false"><img src="image1.gif" name="image1" width="100" height="100" border="0"></a>
0
Comment
Question by:azteccoupe
5 Comments
 

Accepted Solution

by:
saobrien earned 100 total points
ID: 9623888
If I understand your question, you're trying to toggle an image src and an popup opener href using Javascript.  This should be possible using something like:

function flip(name,src) {
    switch(name)
    {
       case "image1":
          opener.location = "http://link1";
          document.images[name].src = src;
          break
       case "image2":
          opener.location = "http://link2";
          document.images[name].src = src;
          break
       default:
          break
    }
}

HTH
0
 
LVL 15

Assisted Solution

by:VincentPuglia
VincentPuglia earned 100 total points
ID: 9624698
Hi,

 if you remove the 'return false', clicking will send the page to the url

<html><head>
<script>
var imageNames = new Array();
imageNames['image1'] = new Image();
imageNames['image1'].src = 'http://members.aol.com/grassblad/images/grassAvatar.jpg'
imageNames['image2'] = new Image();
imageNames['image2'].src = 'http://members.aol.com/grassblad/images/moiAvatar.jpg'

var imgHrefs = new Array()
imgHrefs['image1'] = 'http://members.aol.com/grassblad'
imgHrefs['image2'] = 'http://www.webxpertz.net/forums'

function flip(lnk, img1, img2)
{
  lnk = imgHrefs[img2];
  document.images[img1].src = imageNames[img2].src;
}
</script>
</head>
<body>
<a href="#" onclick="flip(this, 'image1','image2');return false"><img src="http://members.aol.com/grassblad/images/grassAvatar.jpg" name="image1" width="100" height="100" border="0"></a>
</body>
</html>

Vinny
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now