0

I'm writing an image gallery script in which the thumbnail for the currently-viewed image is indicated with a smaller image below the thumbnail. My placeholder is as follows:

<img name="indicator0" alt="indicator>

with indicator1, indicator2, etc. following. In my script, which placeholder has the indicator is called by the variable thumbIndicator. I'd like to be able to do that like this:

document.(thumbIndicator).src = "indicator_image.jpg";

but this has not worked. I've also changed my image placeholder to this:

<img id="indicator0" alt="indicator">

and the script to this:

document.getElementByID(thumbIndicator).src = "indicator_image.jpg";

but that hasn't worked either.

I have been designing websites for a while now, have a fair amount of experience with PHP/MySQL, but am new to JavaScript. Any help is greatly appreciated.

1
  • So is it the case that this can't be done with a variable? I can get it to work by passing a string to getElementId, but I'd like to pass a variable, since there are multiple placeholders. Sounds like it's not possible? Commented Apr 12, 2011 at 14:58

3 Answers 3

3

You need to set the ID of your placeholder image, (which you might be doing, just not in the code above).

<img id="thumbIndicator" alt="alternate text" />

Then to get it:

document.getElementById("thumbIndicator").src = "newfile.png";

In your above code, getElementById had both I and D capitalized, just the I actually is, though.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to pass a string to getElementById:

document.getElementByID("thumbIndicator")

Comments

0
<img src="oldsrc" id="thumbindicator" />

then

document.getElementById('thumbindicator').src = 'newsrc.jpg';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.