473,779 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Swapping images with Javascript

4 New Member
i have a simple page code: pls see below

<HTML>
<BODY>
<a onClick="docume nt.images[0].src='click.gif '"> <IMG SRC="unclick.gi f"></a>

</FORM>
</BODY>
</HTML>

when i click on the unclick.gif image, the image change to click.gif.
i just wonder how the code gonna look like if i wanna change back the click.gif to unclick.gif by clicking the same image

In simple, by clicking one image, the image will swap against each other..
Pls Help..
Jan 8 '07 #1
1 1462
b1randon
171 Recognized Expert New Member
i have a simple page code: pls see below

<HTML>
<BODY>
<a onClick="docume nt.images[0].src='click.gif '"> <IMG SRC="unclick.gi f"></a>

</FORM>
</BODY>
</HTML>

when i click on the unclick.gif image, the image change to click.gif.
i just wonder how the code gonna look like if i wanna change back the click.gif to unclick.gif by clicking the same image

In simple, by clicking one image, the image will swap against each other..
Pls Help..
Expand|Select|Wrap|Line Numbers
  1. var clicked = false;
  2.  
  3. function click(){
  4.     if (clicked)
  5.         document.images[0].src = "clicked.gif";
  6.     else
  7.         document.images[0].src = "unclicked.gif";
  8.     clicked = !clicked;
  9. }
  10.  
and
[HTML]
<html>
<head>
<script src="script.js" ></script>
</head>
<body>
<img src="unclicked. gif" onclick="click( );" />
</body>
</html>
[/HTML]
Jan 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2955
by: Richard | last post by:
I'm beginning to undertake php for the fun of it. Working on a problem I hope can be solved in php. Basically what I have is this: <body> <img name="main" src="image1.jpg"> <a href="#" onMouseOver="document.main.src='image2.jpg'"
2
1586
by: uNConVeNtiOnAL | last post by:
Hi - I have a page that has a button that makes a prompt appear for the user to type input. When they have typed in input, I want the button to change color when the prompt closes. I am trying to do image swapping This snippet will prevent 'null' from appearing initially and successfully records user changes (typing in a comment)
1
5296
by: Terry Haufler | last post by:
I am trying to swap/rotate random flash banners using the following Javascript code. I have 3 flash headers/banners. I can get it to open a page with a random header using document.write(randomHeader) in the chooseHeader() function, but the rest of the page doesn't get displayed with that approach. Instead, what I would like to do is comment the document.write(randomHeader) line, and use the random reference I have in the table cell...
7
1291
by: Jon Glazer | last post by:
I know this is sorta reposting but I want to simplify the issue a bit. Take the following script: function replacemain(s){ var x = document.images; var y = document.images; var pictemp = x.src; x.src = y.src; y.src = pictemp; }
6
2267
by: cjl | last post by:
I have a website which allows people to view interesting radiology cases. It is for teaching radiology residents. It is designed to run in fullscreen or 'kiosk' mode, at 1024 x 768 resolution only. http://www.casespace.net I designed it with firefox (plus the autohide extension) in mind, but also want to support IE. Online and offline it works great in Firefox. Offline it also works
2
2130
by: TuftyTrue | last post by:
Hi, On my site the user can browse to an image with <input type=file etc>. Althrough I have no problem swapping images with: document.getElementById('PictureToDisplay').src = URLtoPictureOnWebServer.src; I cant get it to work with:
1
1371
by: SipherDrakon | last post by:
I know I saw a similar posting about this but mine is a little more complicated and being barely able to understand javascript, i am having a little trouble. <FORM ACTION="http://us.2.p9.webhosting.yahoo.com/forms?login=vansawardsplus" METHOD="post" NAME="Personalize" onsubmit="return ValidateForm();"> <INPUT TYPE="hidden" NAME="form" VALUE="contactpage"> <INPUT NAME="Subject" TYPE="hidden" SIZE=32 VALUE="Additional Information for 68CHSA">...
3
1367
by: Geoff Cox | last post by:
Hello, Way back in 2000 Ken Cox put up this code for swapping images on a button. I cannot work out how to use it so that more than 1 button can use it. I guess the problem is knowing how to deal with the intImage value? Cheers
1
1052
by: Prisoner at War | last post by:
Hi, Everybody, The fucntion below is called by an onLoad <imgattribute, and it is supposed to replace the original image, after three seconds, with another image. This second image shouldl be replaced, after eight more seconds, with the original image. For some reason, JavaScript keeps swapping the images back and forth endlessly -- and not even properly counting out all the seconds specified, after the first time swapping! What's...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.