By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,533 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

Changing an Image from a Select - Simple mistake somewhere?

P: n/a
@sh
Need help again! Here's the head script...

----------------------------------------------------------------------------------------
function Ash_ChangePicFromSelect(TheSource,TheDestination) {
value = TheSource.options[TheSource.selectedIndex].value;
if (value != '')
if (document.images)
// document.images['TheDestination'].src = value;
document.images(TheDestination).src = value;
}
----------------------------------------------------------------------------------------
AND THE BODY...
----------------------------------------------------------------------------------------
<select name="select" class="Style_TextBoxes"
onChange="Ash_ChangePicFromSelect(this,ContentBoxR ow1a)">....................</select>
<img src="public/emailtemplates/boxes/title_specialbreaks_left.gif"
width="111" height="19" id="ContentBoxRow1a" name="ContentBoxRow1a">
----------------------------------------------------------------------------------------

Only on making a select from the SELECT box do I get an error, the error
states...

'document.images[...]' is null or not an object

Have I screwed up how I'm passsing the name of the image? Appreciate your
help again geniuses!!
Dec 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
@sh wrote:
[...]
function Ash_ChangePicFromSelect(TheSource,TheDestination) {
value = TheSource.options[TheSource.selectedIndex].value; ^^^^^^^
This defines a global variable. Use

var value = ...

instead.
if (value != '') { if (document.images && document.images[TheDestination]
{ // document.images['TheDestination'].src = value;

document.images[TheDestination].src = value;
}
document.images(TheDestination).src = value;
document.images is a collection, not a method.

} }
[...]
AND THE BODY...
0. Subjects should be concise.
1. No need to SHOUT here.
2. Posting width should not exceed 80 characters.
3. Indent code using 2 or 4 spaces, not tabs.

news:news.newusers.questions
[...]
<select name="select" class="Style_TextBoxes"
onChange="Ash_ChangePicFromSelect(this,ContentBoxR ow1a)">[...]</select>>
<img src="public/emailtemplates/boxes/title_specialbreaks_left.gif"
width="111" height="19" id="ContentBoxRow1a" name="ContentBoxRow1a">
The `alt' attribute is missing. <URL:http://validator.w3.org/>
[...]
Only on making a select from the SELECT box do I get an error, the error
states...

'document.images[...]' is null or not an object


Because there is no `img' element with name or ID `TheDestination'.
PointedEars
Dec 19 '05 #2

P: n/a
Thomas 'PointedEars' Lahn wrote:
@sh wrote:
if (document.images

&& document.images[TheDestination]

)
Dec 19 '05 #3

P: n/a
@sh wrote:
Need help again! Here's the head script...

----------------------------------------------------------------------------------------
function Ash_ChangePicFromSelect(TheSource,TheDestination) {
value = TheSource.options[TheSource.selectedIndex].value;
if (value != '')
if (document.images)
// document.images['TheDestination'].src = value;
document.images[TheDestination].src = value;
document.images(TheDestination).src = value;
}
----------------------------------------------------------------------------------------
AND THE BODY...
----------------------------------------------------------------------------------------
<select name="select" class="Style_TextBoxes"
onChange="Ash_ChangePicFromSelect(this,ContentBoxR ow1a)">....................</select>
onChange="Ash_ChangePicFromSelect(this,'ContentBox Row1a')"

Mick
<img src="public/emailtemplates/boxes/title_specialbreaks_left.gif"
width="111" height="19" id="ContentBoxRow1a" name="ContentBoxRow1a">
----------------------------------------------------------------------------------------

Only on making a select from the SELECT box do I get an error, the error
states...

'document.images[...]' is null or not an object

Have I screwed up how I'm passsing the name of the image? Appreciate your
help again geniuses!!

Dec 19 '05 #4

P: n/a
Thomas 'PointedEars' Lahn said the following on 12/19/2005 2:51 PM:
@sh wrote:

[...]
function Ash_ChangePicFromSelect(TheSource,TheDestination) {
value = TheSource.options[TheSource.selectedIndex].value;
^^^^^^^
This defines a global variable. Use

var value = ...

instead.


Irrelevant to the question at hand.
if (value != '')


{
if (document.images


&& document.images[TheDestination]
{
// document.images['TheDestination'].src = value;


document.images[TheDestination].src = value;
}

document.images(TheDestination).src = value;

document.images is a collection, not a method.

}
}
Lots and Lots more Irrelevant material.
[...]
AND THE BODY...

0. Subjects should be concise.


Subjects are irrelevant.
1. No need to SHOUT here.
2. Posting width should not exceed 80 characters.
3. Indent code using 2 or 4 spaces, not tabs.
news:news.newusers.questions

[...]
<select name="select" class="Style_TextBoxes"
onChange="Ash_ChangePicFromSelect(this,ContentBo xRow1a)">[...]</select>>
<img src="public/emailtemplates/boxes/title_specialbreaks_left.gif"
width="111" height="19" id="ContentBoxRow1a" name="ContentBoxRow1a">

The `alt' attribute is missing. <URL:http://validator.w3.org/>


Irrelevant to the question at hand.
[...]
Only on making a select from the SELECT box do I get an error, the error
states...

'document.images[...]' is null or not an object

Because there is no `img' element with name or ID `TheDestination'.


All that to finally get to something relevant to the problem.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

Dec 19 '05 #5

P: n/a
@sh
Mick you're a star, thanks very much!! I cannot believe it was failing to
work simply because I'd missed the single quotes!

Many thanks for YOUR clear concise reply.

Cheers and Merry Xmas!
Dec 20 '05 #6

P: n/a
@sh
Thanks Randy, agreed.

Merry Xmas!
Dec 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.