Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: Dr. Nick
I need to add two strings together to form a variable name. The purpose of the function is to replace an image with the name "truck" with another pre-loaded image "truck_2".
ie:
function replace(img)
{
img.src = img_2.src;
}I call the function like this: replace(truck);
Without the variables, the function should work like this:
function replace()
{
truck.src = truck_2.src;
}
Sorry if it's confusing! If you don't get what I mean, please ask!Thanks!

Are you sure you want to do this that way? Turning the contents of a variable into a variable borders on self-modifying code, which to my knowledge javascript doesn't support (except in the sense that javascript can output javascript) Consider one of the following approaches:
1. Is it possible for you to rename the image files to something like
"truck_1.jpg"
"truck_2.jpg"
...
This way the javascript could dynamically change the source of the img. This is the approach I went with on the homepage of www.sharingds.org (rotating pictures on the top.)2. If renaming the files isn't an option, consider having an array of the file names, and that way the javascript could just go through the array to reload and swap the images to your liking.
If either of these approaches sounds like it might work, feel free to post back for help implementating them.
Sorry I couldn't solve the original problem,
-SN

Thanks for the suggestions. I think I'm just going to create an array of images to solve my problem.

![]() |
addRow() in JTable....
|
Not work, Printer Prog fo...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |