473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Swapping images with Javascript

i have a simple page code: pls see below

<HTML>
<BODY>
<a onClick="document.images[0].src='click.gif'"> <IMG SRC="unclick.gif"></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 1432
b1randon
171 Expert 100+
i have a simple page code: pls see below

<HTML>
<BODY>
<a onClick="document.images[0].src='click.gif'"> <IMG SRC="unclick.gif"></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
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="#"...
2
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...
1
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...
7
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 =...
6
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...
2
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 =...
1
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...
3
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.