PDA

View Full Version : Changing image source help needed


jasonrg
02-05-2003, 05:01 PM
I would like to write a js function that I can use to change the source of different images on the screen. This function would be called from different links thorughout the page. I want to be able to pass in the name of the image that I want to change and the new source name that I would like it changed to. I am having difficulty however trying to specify the location of the src since each is different. Anyone have any suggestions? Thanks!!

JasonRG

joeframbach
02-05-2003, 05:22 PM
click the 'search' link at the top of the page. there are too many threads like this one.

jasonrg
02-05-2003, 05:35 PM
Thanks for the effort! I've already tried the search but cannot locate exactly what I'm looking for.

whammy
02-06-2003, 12:42 AM
Each img tag needs an "id" attribute, then it becomes part of the Document Object Model, like:

<img id="myDisneyPic" ...other stuff here... />

Then you can refer to the source property such as:

document.images.myDisneyPic.src

jasonrg
02-06-2003, 02:08 AM
Originally posted by whammy
Each img tag needs an "id" attribute, then it becomes part of the Document Object Model, like:

<img id="myDisneyPic" ...other stuff here... />

Then you can refer to the source property such as:

document.images.myDisneyPic.src

whammy,

thanks for the info. I'm able to switch source for a single pic on the page. I'm setting up a function that I want to pass in the id of any pic on the page and change it's source. I was having trouble referencing the source using a variable but have since figured out what I had incorrect. Below is the line of code I had:

document.images.[name].src

where I should have had:

document.images[name].src

with 'name' being the variable that is passed into the function. As you can see, I had an extra . that was not needed. I appreciate your help!:thumbsup:

JasonRG

glenngv
02-06-2003, 07:39 AM
image rollover??
http://codingforums.com/showthread.php?s=&threadid=11673