Changing an Image from a Select - Simple mistake somewhere?

@

@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,ContentBoxRow1a)">....................</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!!
 
T

Thomas 'PointedEars' Lahn

@sh said:
[...]
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.

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

The `alt' attribute is missing. said:
[...]
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
 
M

mick white

@sh said:
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,ContentBoxRow1a)">....................</select>
onChange="Ash_ChangePicFromSelect(this,'ContentBoxRow1a')"

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!!
 
R

Randy Webb

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.

[...]
<select name="select" class="Style_TextBoxes"
onChange="Ash_ChangePicFromSelect(this,ContentBoxRow1a)">[...]</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.
 
@

@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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top