Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / April 2006



Tip: Looking for answers? Try searching our database.

Simple image swap not working...Why?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed Jay - 28 Apr 2006 18:30 GMT
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.
Signature

Ed Jay (remove 'M' to respond by email)

VK - 28 Apr 2006 18:41 GMT
> Why doesn't the following swap images?
>
[quoted text clipped - 4 lines]
> </script>
> </head><body>

because you did not enclose the URI string in quotes:

document.images.image1.src="/images/1stimage.gif";
Ed Jay - 28 Apr 2006 18:57 GMT
VK scribed:

>> Why doesn't the following swap images?
>>
[quoted text clipped - 8 lines]
>
>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";}
Signature

Ed Jay (remove 'M' to respond by email)

Lee - 28 Apr 2006 19:13 GMT
Ed Jay said:

>VK scribed:
>
[quoted text clipped - 16 lines]
>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.

Signature

                       

Ed Jay - 28 Apr 2006 20:38 GMT
Lee scribed:

>Ed Jay said:
>>
[quoted text clipped - 23 lines]
>Open each image directly in your browser and copy the full URL
>into your code.

Thanks, Lee. Image path was the problem.
Signature

Ed Jay (remove 'M' to respond by email)

Tony - 29 Apr 2006 22:45 GMT
> Ed Jay said:
>
[quoted text clipped - 23 lines]
> 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
Ed Jay - 30 Apr 2006 06:38 GMT
Tony scribed:

>> Ed Jay said:
>>
[quoted text clipped - 28 lines]
>
>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

:-)
Signature

Ed Jay (remove 'M' to respond by email)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.