Solved

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

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to dynamically set the form action using jQuery.

743 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

10 Experts available now in Live!

Get 1:1 Help Now