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

Simple image swap not working...Why?

Why doesn't the following swap images?

<head>
<javascript type="text/javascript">
function swapImage() {document.images.image1.src=/images/1stimage.gif;}
function swapBack() {document.images.image1.src=/images/2ndimage.gif;}
</script>
</head><body>

<a href=url onMouseOver=swapImage(); onMouseOut=swapBack();>
<img name="image1" src="/images/1stImage.gif"></a>

On page load I see 1stimage. When I mouseover, the image disappears and
leaves a blank in its place. Nothing changes afterwards when I mouseOut or
mouseOver.
--
Ed Jay (remove 'M' to respond by email)
Apr 28 '06 #1
5 2771
VK

Ed Jay wrote:
Why doesn't the following swap images?

<head>
<javascript type="text/javascript">
function swapImage() {document.images.image1.src=/images/1stimage.gif;}
function swapBack() {document.images.image1.src=/images/2ndimage.gif;}
</script>
</head><body>


because you did not enclose the URI string in quotes:

document.images.image1.src="/images/1stimage.gif";

Apr 28 '06 #2
VK scribed:

Ed Jay wrote:
Why doesn't the following swap images?

<head>
<javascript type="text/javascript">
function swapImage() {document.images.image1.src=/images/1stimage.gif;}
function swapBack() {document.images.image1.src=/images/2ndimage.gif;}
</script>
</head><body>


because you did not enclose the URI string in quotes:

document.images.image1.src="/images/1stimage.gif";


Sorry, but I didn't include the quotes. Actual code is as you've shown,
i.e.,

function swapImage() {document.images.image1.src="/images/1stimage.gif";}
function swapBack() {document.images.image1.src="/images/2ndimage.gif";}
--
Ed Jay (remove 'M' to respond by email)
Apr 28 '06 #3
Lee scribed:
Ed Jay said:

VK scribed:

Ed Jay wrote:
Why doesn't the following swap images?

<head>
<javascript type="text/javascript">
function swapImage() {document.images.image1.src=/images/1stimage.gif;}
function swapBack() {document.images.image1.src=/images/2ndimage.gif;}
</script>
</head><body>

because you did not enclose the URI string in quotes:

document.images.image1.src="/images/1stimage.gif";


Sorry, but I didn't include the quotes. Actual code is as you've shown,
i.e.,

function swapImage() {document.images.image1.src="/images/1stimage.gif";}
function swapBack() {document.images.image1.src="/images/2ndimage.gif";}


You see how you waste resources when you don't copy and paste the
actual code? The pathnames to your images are probably wrong.
Open each image directly in your browser and copy the full URL
into your code.


Thanks, Lee. Image path was the problem.
--
Ed Jay (remove 'M' to respond by email)
Apr 28 '06 #4
Lee wrote:
Ed Jay said:
VK scribed:

Ed Jay wrote:

Why doesn't the following swap images?

<head>
<javascript type="text/javascript">
function swapImage() {document.images.image1.src=/images/1stimage.gif;}
function swapBack() {document.images.image1.src=/images/2ndimage.gif;}
</script>
</head><body>

because you did not enclose the URI string in quotes:

document.images.image1.src="/images/1stimage.gif";


Sorry, but I didn't include the quotes. Actual code is as you've shown,
i.e.,

function swapImage() {document.images.image1.src="/images/1stimage.gif";}
function swapBack() {document.images.image1.src="/images/2ndimage.gif";}

You see how you waste resources when you don't copy and paste the
actual code? The pathnames to your images are probably wrong.
Open each image directly in your browser and copy the full URL
into your code.


Actually, the way the paths are defined, it's looking for directory
'images' under the root.

I'd be willing to bet that removing the preceding '/' would help - and a
bit of time spent learning the difference between absolute & relative paths
Apr 29 '06 #5
Tony scribed:
Lee wrote:
Ed Jay said:
VK scribed:
Ed Jay wrote:

>Why doesn't the following swap images?
>
><head>
><javascript type="text/javascript">
> function swapImage() {document.images.image1.src=/images/1stimage.gif;}
> function swapBack() {document.images.image1.src=/images/2ndimage.gif;}
></script>
></head><body>

because you did not enclose the URI string in quotes:

document.images.image1.src="/images/1stimage.gif";

Sorry, but I didn't include the quotes. Actual code is as you've shown,
i.e.,

function swapImage() {document.images.image1.src="/images/1stimage.gif";}
function swapBack() {document.images.image1.src="/images/2ndimage.gif";}

You see how you waste resources when you don't copy and paste the
actual code? The pathnames to your images are probably wrong.
Open each image directly in your browser and copy the full URL
into your code.


Actually, the way the paths are defined, it's looking for directory
'images' under the root.

I'd be willing to bet that removing the preceding '/' would help -


No, but adding either the path to root or a single period would.
../images/image.gif
and a
bit of time spent learning the difference between absolute & relative paths


:-)
--
Ed Jay (remove 'M' to respond by email)
Apr 30 '06 #6

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

Similar topics

1
by: Weston C | last post by:
I'm working on a small javascript application where I'd like to get one behavior when a user clicks on an image (image swap), but when they simply hold down the mouse button for a second, they get...
1
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...
12
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...
4
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
2
by: Barkster | last post by:
I have a image that I want to click and when clicked that image will be swapped and then show a hidden div. When another image like it is clicked it will swap image and hide that text and so on. ...
29
by: Knut Olsen-Solberg | last post by:
I try to change the text in a <p> using getElementById(). I wonder what properties exists, and which one to use here. (The following does not work.) Regards Knut ______________________ ...
7
by: KiwiBrian | last post by:
On a web page I have a graphic for a Shopping Cart Submit button. It is within a form and working fine. I would like to perform an image swap to an identical graphic of a different colour when I...
1
by: gconrads | last post by:
Appreciate any advice: I'm working on a small script to swap out an image using javascript, this is my first attempt at using javascript. My method works fine in Firefox, but not in Safari....
14
by: =?Utf-8?B?Sm9lIFRob21wc29u?= | last post by:
I have a Windows form program written in C# 2005. I continually read a stream of data via TCP that comes from a video camera (NTSC). When I have all the data for one frame I update a picturebox...
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: 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...
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...
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,...

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.