Solved

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

Posted on 2003-10-26
5
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

751 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