Ie7 Default Form Method Is "get". How Can I Tell If It's User-entered Or Default?
Solution 1:
IE's behaviour is correct!(*) According to DTD:
method (GET|POST) GET-- HTTP method used to submit the form--
or, in the XHTML DTD:
method (get|post) "get"
that means if the method
attribute is omitted, not only does the form submit as GET by default, but the DOM actually should contain an Attr
node for method
with the DTD defaulted value GET
.
(*: well, sort of. IE is using the XHTML lower-case default in an HTML document where it should be the upper-case. Not that it really matters as the attribute is case-insensitive in HTML anyhow. And hey! It's IE getting the standard more-right than all the other browsers. It's a miracle!)
So how do you tell that the Attr
node was put there because of DTD attribute defaulting and not because it was in the source? With the DOM Level 1 Core specified flag:
var form= document.getElementById('myform');
var attr= form.getAttributeNode('method');
var isomitted= attr===null || !attr.specified;
Solution 2:
This doesn't seem to be in violation of the HTML form spec, which states:
This attribute specifies which HTTP method will be used to submit the form data set. Possible (case-insensitive) values are "get" (the default) and "post". See the section on form submission for usage information
Solution 3:
(How do I reply to a specific reply?) (in reply to bobice:)
IE's behaviour is correct!
If I read the relevant specs correctly, these are all the case in conformant implementations (which IE is not):
form.method == "get"/* IETF and W3C HTMLs and XHTMLs */ || form.method == "GET"/* HTML5* */
form.hasAttribute ("method") == false
form.getAttribute ("method") == ""
form.getAttributeNode ("method") == null
In Chrome "8.0.552.28 beta" on Linux, I get (also not correct)
var form = document.createElement ("form")
undefined
form.method == "get" || form.method == "GET"false/* actual value is "" */
form.hasAttribute ("method") == falsetrue
form.getAttribute ("method") == ""false/* actual value is null */
form.getAttributeNode ("method") == nulltrue
- In HTML5, method is an enumerated attribute equal to one of GET, POST, PUT, DELETE. form.method must "reflect" the method attribute, which in the case of an enumerated attribute means the specified value if it matches one of the valid values or else the first valid value. (I may be reading this slightly wrong, but that is my interpretation.)
Post a Comment for "Ie7 Default Form Method Is "get". How Can I Tell If It's User-entered Or Default?"