473,467 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Switch between images

I´m trying to find out how to switch between an image by a mouseclick.

The function should check if the image is on or off but it doesn´t work.
What´s wrong?

Below the script.

start_on = new Image;
start_on.src = "images/start_on.jpg";
start_off = new Image;
start_off.src = "images/start_off.jpg";

function switch(image) {
document.images[image].src = (document.images[image].src.indexOf("_off")==-1)? eval(image + "_off.src"); eval(image + "_on.src")
}

<img border="0" name="start" src="images/start_on.jpg" onClick="switch('start')">

Thanks
John

http://members.home.nl/jpeskens
Jul 20 '05 #1
3 8316
"John" <jp**********@spamhome.nl> schreef in bericht news:bo**********@news4.tilbu1.nb.home.nl... I´m trying to find out how to switch between an image by a mouseclick.

The function should check if the image is on or off but it doesn´t work.
What´s wrong?


document.images[image].src =
(document.images[image].src.indexOf("_off")==-1) ?
image + "_off.src" : image + "_on.src";

JW

Jul 20 '05 #2

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:3f***********************@news.wanadoo.nl...

document.images[image].src =
(document.images[image].src.indexOf("_off")==-1) ?
image + "_off.src" : image + "_on.src";


Error, sorry. Should be:

document.images[image].src =
(document.images[image].src.indexOf("_off")==-1) ?
start_off.src : start_on.src;
JW


Jul 20 '05 #3
Hoi Janwillem,
Ik heb het al gezien. Het lag aan de puntkomma. Moet een dubbele punt zijn.

Bedankt in ieder geval

John

htpp://members.home.nl/jpeskens
"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht news:3f***********************@news.wanadoo.nl...

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:3f***********************@news.wanadoo.nl...

document.images[image].src =
(document.images[image].src.indexOf("_off")==-1) ?
image + "_off.src" : image + "_on.src";


Error, sorry. Should be:

document.images[image].src =
(document.images[image].src.indexOf("_off")==-1) ?
start_off.src : start_on.src;


JW



Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andre | last post by:
Hi, I have some function to Preload images and make MouseOver etc.. But when a put a Switch statement in one of my function (MouseOver), a receive an error on body load in my preload...
13
by: Richard | last post by:
I've been looking at implementing switch/case on my photo gallery. Most of the sites I've seen so far, only show the bare basics. With no real practical examples. As brucie does with his...
8
by: Richard | last post by:
I am slowly understanding how this all comes together and feel it is an answer to my needs. By using a form with an image as my input, I can assign a value to the image. That I can not do with an...
1
by: roN | last post by:
Hi, I have 3 small images and 3 big images, i would like to display the big one, when the small one is clicked, I tried: IA1 = new Image(); IA1.src = "./images/IA-demo-big_1.jpg"; /*...
19
by: Bruintje Beer | last post by:
Hello, I have a html page with a main picture but I want the main picture switch every 3 seconds to a new main pictures. How can I do this in java script. John
4
by: JoJo | last post by:
I followed along in Jeremy Keith's book "DOM Scripting" on how to make a image viewer that changes on clicking links. It is up for demo at: http://jojowebdesign.com/dom1.html My question is...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
10
by: stewdizzle | last post by:
I am setting up a small site for personal use. It consists of a form that transfers inputed values to an html template. The ouput is code that i can use to quickly post on a website. In the...
2
by: Annalyzer | last post by:
My form looks like this: <form action="handle_event.php" method="POST" enctype="multipart/form-data"> <table id="event_edit" border="0"> <tr> <td> ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...
0
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...
0
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...

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.