471,350 Members | 1,586 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Form images don't appear in form.elements

Apparently, form elements of type

<input type="image" src="...>

are not included in the form's elements[] collection.

I don't understand why not; according to DOM2, all form control
elements in the form are part of the elements collection. Further,
this element doesn't appear in the (DOM0) document.images
collection either; so it's really not well-accounted for.

And, to the contrary, the <input type="image"> element *does* have
a 'form' property, whose value is its parent form. This seems
completely wrong: if you count the nodes in form.elements, it
really should be equal to the number of nodes that reference
the form element in their form property.

Is there an explanation for this, or was this behavior chosen
strictly to mimic Internet Explorer's behavior? Or, am I doing
something wrong?

Thanks,

hj

Illustration:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<!-- This behavior doesn't seem to be affected if I
omit the DTD, to fall back to quirks mode -->
<html><head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>Img form elements</title>
<script type="text/javascript">
function ecount(f) {
var collection,i,node;
alert(f.elements.length + " elements in form, and \n" +
document.images.length + " images in document.images");
collection = f.getElementsByTagName('*');
alert(collection.length + " descendant nodes in form");
for (i=0; i<collection.length; i++) {
node = collection[i];
alert("Form descendant node: '" + node.nodeName +
"'.form='" + node.form + "'");
}
return false;
}
</script></head><body>
<h1>Img form elements</h1>
<div>
<form action="" onsubmit="return ecount(this)">
<p>There are 2 elements in this form:<br><br>
&lt;input type="text"&gt;: <input type="text" name="txt" onblur="ecount(this.form)"><br>
and &lt;input type="image"&gt;: <input type="image" src="../images/awki.png">
</p><p>
Click the image, or blur() the text input to count fields in the
form's elements array.</p>
</form></div>
</body></html>
Jul 23 '05 #1
1 1498
Howard Jess wrote:
Apparently, form elements of type

<input type="image" src="...>

are not included in the form's elements[] collection.

I don't understand why not; according to DOM2, all form
control elements in the form are part of the elements
collection.
They don't always not appear in the elements collection, but it would be
reasonable to say that it would not be a good idea to expect to be able
to find them there (as they commonly will not be present).
Further, this element doesn't appear in the (DOM0)
document.images collection either;
It would be unexpected for them to appear in - document.images - as it
is explicitly a collection of IMG elements, no elements that happen to
be displaying images (such as maybe OBJECT).
so it's really not well-accounted for.
It is certainly a unhelpful peculiarity where forms are concerned.

<snip> Is there an explanation for this, or was this behavior
chosen strictly to mimic Internet Explorer's behavior?
Or, am I doing something wrong?

<snip>

I think you will find that this behaviour originates with a Netscape
browsers. Netscape 4 had no means of referencing these elements (as they
did not even support event handlers), and that may have also been true
for earlier versions (thus pre-dating scriptable IE versions).

Richard.
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by twopeak | last post: by
5 posts views Thread by Richard Cornford | last post: by
10 posts views Thread by Mohit Gupta | last post: by
3 posts views Thread by Simon | last post: by
25 posts views Thread by Dave | last post: by
11 posts views Thread by shankwheat | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.