Solved

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

Posted on 2003-10-26
5
319 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

623 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