Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-10-26
5
Medium Priority
?
323 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 400 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 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

722 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