/    Sign up×
Community /Pin to ProfileBookmark

absolutely stupid question about form

isn’t it an INPUT type=’image’ a form’s element? Why so?:

[code=php]
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<meta http-equiv=”Content-Style-Type” content=”text/css”>
<meta http-equiv=”Content-Script-Type” content=”text/javascript”>
<script language=”JavaScript” type=”text/JavaScript”>
onload=function(){
alert(document.forms[0].elements.length);//why 0 ?
}
</script>
</head>
<body>
<form>
<input name=”foo” type=”image” src=”00.jpg”>
</form>
</body>
</html>
[/code]

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 30.2005 — Only text inputs are defined as form controls. http://www.w3.org/TR/REC-html40/interact/forms.html#form-controls
Copy linkTweet thisAlerts:
@KorauthorMar 30.2005 — well, hm... I was not talking about controls (anyway, after all an input typed image can submit it's image coordinates, so that, somehow, it acts as a control, after all)... I was just trying to reference that element as a form's element. I am able to do that using DOM methods, but it looks weird to me that such an input element is not considered as a form's element....
Copy linkTweet thisAlerts:
@Orc_ScorcherMar 30.2005 — Backwards compatibility. Navigator 2 didn't add type="image" elements to the collection and to be compatible with old scripts Nav3 didn't change that behaviour. Since then, every new browser has avoided to break this sacred tradition.
Copy linkTweet thisAlerts:
@KorauthorMar 30.2005 — ? Well... hm... passing through browsers variants, almost all the time the new ones [b]added[/b] the new behaviours to the old ones... Shall I understand that the "wise guys" forgot to add the typed image to the form's elements as well... ? That is a memorable lack of memory ? ?
Copy linkTweet thisAlerts:
@FangMar 30.2005 — Only form controls are included in the [I]elements[/I] collection. So if it is not listed as a control ...
Copy linkTweet thisAlerts:
@Orc_ScorcherMar 30.2005 — Adding new features is fine as long as it doesn't break (too many) existing pages. Since many form validation used hardcoded values such a change would (it still would, I bet) have caused mayor damage. People would have whined and buggered Netscape all day long if what was elements[2] before became elements[3] suddenly. I'm pretty certain this wasn't an oversight but a conscious design decision.
Copy linkTweet thisAlerts:
@KorauthorMar 30.2005 — as long as it is an INPUT and, furthermore, as long as it can submit, it [b]should[/b] be a control. It [b]acts[/b] as a control... It can submit values to the server, so that [b]it interacts[/b] with the other form's elements. If so, how is that it is not a form's element?
Copy linkTweet thisAlerts:
@Orc_ScorcherMar 30.2005 — <input type="image"> is a form control. See HTML 4.01 17.4.1 if you need proof.
Copy linkTweet thisAlerts:
@FangMar 30.2005 — The W3C is a little ambiguous as in '17.2.1 Control types' only text inputs are included.

That is the html side but the [I]elements[/I] array is JavaScript. The older browsers (NN4) did not have support for events in inputs of type image. As [B]Kor[/B] wrote a possible oversight not to add it to the elements array in a later version of JavaScript.

The [I]form[/I] is full of bugs and exceptions; look at the differences in CSS or DOM implementation between the browsers!
Copy linkTweet thisAlerts:
@KorauthorMar 31.2005 — Of course, there are DOM solutions to reach the image file element (for those who may encounter the same problem for the future):

[i]root[/i].getElementsByName('inputname')[0]

or

[i]root[/i].getElementsByTagName('input')[index];

or circle through contioned by type

Still, it is strange that javascript 1 has not included the image file into the form's elements' collection
Copy linkTweet thisAlerts:
@Orc_ScorcherMar 31.2005 — In case you are interested in browser development history, [url=https://bugzilla.mozilla.org/show_bug.cgi?id=61413#c4]here[/url] is the story behind it, direct from JavaScript's creator.
Copy linkTweet thisAlerts:
@KorauthorMar 31.2005 — yeap, thanks, now I see that there is a bug, after all, but the resons for ommiting the image inputs from form's collections are quite resonable... At least they [i]were[/i] resonable enough at the time.... ?
×

Success!

Help @Kor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...