473,391 Members | 1,472 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,391 software developers and data experts.

Image Swap

Could someone tell me what is wrong with this function?
function imageNext(){

if ( document.part.src == "images/returnAdapter.gif"){
document.part.src = "images/valveIntake.gif";
document.getElementById("c").style.color = "black";
document.getElementById("d").style.color = "red";

The image name attribute is "part". But the image is not changing.

Thanks, Sybil
Jul 20 '05 #1
1 2620
sd*@bdgrp.com (Sybil) writes:
Could someone tell me what is wrong with this function?
In which browser?
function imageNext(){ if ( document.part.src == "images/returnAdapter.gif"){
The assumption that "document.part" refers to the element with name
"part", doesn't hold in all browsers. A safer way of referencing the
element is

You compare the value of the src property to a releative path.
Most browsers (including IE6) changes to property to the absolute path.
E.g., if I create an image as:
<img src="../../PicA.png" id="foo">
and then read the src value again with javascript (in IE 6)
the result is
That means that your comparison will alway fail.
You should test that the src *ends* with your string, e.g., with a
regular expression:

if (/images\/returnAdapter.gid$/.test(document.images['part'].src) {
document.part.src = "images/valveIntake.gif";
Again, "document.imagesŲ is safer.
document.getElementById("c").style.color = "black";
document.getElementById("d").style.color = "red";

A "}" is missing here (just to be pedantic :)

Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

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

Similar topics

by: John | last post by:
I am rotating images of different dimensions. My problem is that when a new image is displayed in a new position which had an image of a different dimension, the old image is first stretched to the...
by: Frank Bishop | last post by:
I have been trying to do image swaps and my second image does not show up, it just goes to a blank image on the mouseover. I have Windows XP SP2 and it prompts me to allow blocked content when the...
by: Matthew | last post by:
Hi all I'm looking for a solution that can be used in a calendar/gig guide scenario where each day is represented by a dot image. Now this dot must do the following 1. When the mouse goes...
by: broms10 | last post by:
I need help. I have a little button that says "next" below a big image, let“s call it "image1", when I press the button I want to swap the big image to "image2". And then if I press it again I...
by: Charlie King | last post by:
As I understand it, the use of FIR* to replace heading tags with images in visually enabled CSS browsers is now frowned upon on the basis that some screen readers will *nor* read back text that is...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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: 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...
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,...
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...
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...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.