Problems with a form....

N

Naby

Hi guys

Here's my question:

I have a form wich contains an image field. I'm trying to change the image
dynamically using javascript but it doesn't work!

here's the statement I'm trying to use: document.myform.myimage.src =
"some.gif"

the actual error message is: "document.myform.myimage is null or not an
object".

what can it be?


Thanks for your quick reply

Naby.
 
K

Kevin Spencer

Perhaps you should read the tutorial that you copied that snippet from. It
looks like an example of code, not something intended to be copied and
pasted, but understood and applied.

If you don't know where you copied it from, I'll explain it. The tokens
separated by dots are objects in the HTML Document Object Model. "document"
is a generic term for the HTML document object itself. Items contained in an
object are denoted by dots and their names. So, in your case "myform" is a
reference to a form on the page. Note that it is not a generic reference,
but a specific reference to a specific form in that document (there can be
many forms in an HTML document). "myimage" is a reference to a specific
image object that is contained in the form referenced. "src" is a reference
to the "src" property (attribute) of the image object. Finally, the equals
sign is an assignment operator that assigns a value (to the right of the
equals sign) to an object (to the left of the equals sign). In this case,
you seem to be assigning the name "some.gif" to the "src" attribute of the
image object. The "src" attribute (property) of an image object is a string
that signifies the URL of the resource in question.

If ANY part of the statement is not correct, the whole statement fails. In
this case, the error message is very informative, telling you that
"document.myform.myimage is null or not an object". In other words, you are
referencing something that does not exist. Which part of your reference is
wrong? Only you could know that. Hopefully my explanation will provide the
information that you need to make this determination.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
N

Naby

Thanks fro your reply kevin

the statement you are talking about doesn't come from a tutiorial....I was
just trying to explain de problem as generically as I could since the actual
code is in french. Here it is:

document.monformulaire.De1.src = "de2.gif";

"monformulaire " refers to my form and "De1" is an image on that form. All
I'm trying to do is to replace it with another image
 
K

Kevin Spencer

Hi Naby,

Images are tricky, because they are in a collection all by themselves
(unless you're talking about an image form element, which is another animal
altogether, and resides in the form's elements Collection. What you need is
something like the following (and make sure the script appears AFTER the
image in the document):

<body>
....
<p>
<img border="0" name="De1" src="mmc.gif"></p>

<script>document.images["De1"].src="/warning.gif"</script>

....
</body>

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
Top