Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 1st, 2006, 05:54 AM
Authorized User
 
Join Date: Aug 2006
Posts: 20
Thanks: 4
Thanked 0 Times in 0 Posts
Default swap image onclick

Hi there!
Currently i am facing problem with swaping an image using javascript.
What i'm trying to do is when i click on the hyperlink the image is changed to another image.
<a href="#" onclick="ChangePic()"><image name="img" src="somepic.jpg"></a>
I have done till here...when i click the link the new image is loaded
but when i again click the pic the other image ... how to keep track which image to load???
i want to toggle between two images
i'm a newbie so plz...

HELP!!!!!!!!!
 
Old November 8th, 2006, 01:35 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii The Beginner!!
Hope this will help you
<script>
function ChangePic(currentPicToShow,val)
{
hrIds=document.getElementsByName("hrid")
imgObj=document.getElementsByName("imgname")
str=imgObj[val].src
hrIds[val].onclick=function(){ChangePic(str,val)};
imgObj[val].src=currentPicToShow
}
</script>

<a name="hrid" href="#" onclick="ChangePic('callsheet.jpg',0)"><image name="imgname" src="exit.jpg" ></a>
<a name="hrid" href="#" onclick="ChangePic('callsheet.jpg',1)"><image name="imgname" src="exit.jpg" ></a>
<a name="hrid" href="#" onclick="ChangePic('exit.jpg',2)"><image name="imgname" src="callsheet.jpg"></a>


Cheers :)

vinod
The Following User Says Thank You to vinod_yadav1919 For This Useful Post:
The Beginner (December 18th, 2008)
 
Old November 8th, 2006, 08:42 AM
Authorized User
 
Join Date: Aug 2006
Posts: 20
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Thanx a lot...
i hope this helps me out...







Similar Threads
Thread Thread Starter Forum Replies Last Post
how to swap the table column value shahidmca SQL Language 2 July 31st, 2007 06:43 PM
Image button onclick msbsam ASP.NET 2.0 Basics 0 December 30th, 2006 04:47 AM
Swap Images Mike707 Dreamweaver (all versions) 3 December 18th, 2006 01:05 PM
Problem to Swap two number in C# furqanms C# 1 June 5th, 2006 05:12 PM
How to Swap two integers without temp variable ramk_1978 C# 2 February 28th, 2006 08:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.