473,378 Members | 1,156 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 1596
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: twopeak | last post by:
Hello I'm making a script, that should allow users to change a select box, and this changes the alt and the src of several images. I have made a script (see under) that exactly does what it's...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
1
by: Dave | last post by:
Hi all, I was trying to make an image submit button with a rollover and discovered to my suprise that there is no way to access a form element of the "image" type. I tried specifying it by name...
0
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main...
10
by: Mohit Gupta | last post by:
Hello Friends I have written a simple HTML page in aspx I have added form elements like "textBox", "Hidden fields", "images", "radio buttons" to the html form I am posting the data back to the...
3
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a...
25
by: Dave | last post by:
Hello. In trying to get an anchor element to stylistically match an input or button element, I find that the button and input cannot be styled according to the 2.1 CSS spec. For example, I...
11
by: shankwheat | last post by:
I have a function which passes text from txtdebt to debtsbox which works fine. However, I want to add code which examines the value of debtsbox and if any of the values the user entered contain the...
1
by: jeddiki | last post by:
Hello, I have made a nice opt-in form and tested it in Moz FF and it looks fine. But in IE the elements don't line up properly. I think I am nearly there but can not get these elements...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.