An input in a form named 'action' overrides the form's action property. Is this a bug?
I would not call this a bug. This effect occurs, because attributes can be read by using element.attributename
and named inputs inside a form can be accessed in the same way, formelement.inputname
. If there is an attribute and an input with the same name, there is no guarantee which one will be used. It probably behaves differently in different browsers.
I personally use getAttribute
if I am reading a known attribute that was included in the markup or added using setAttribute
in JavaScript. For dynamic values like, for example, the checked
attribute of a checkbox, I don't use getAttribute
. But this is more a question of personal preference, I guess.
I am fighting this behaviour at the moment too (7 years later!)
It is very hacky, but you are able to access and call the action
getter directly by using the following.
Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, 'action').get.call(document.forms[0]);