Sunday, 18 August 2013

HTML form onsubmit passing this.id; yielding unexpected value

HTML form onsubmit passing this.id; yielding unexpected value

I'm working on a website and was experiencing this problem, so I
simplified it as much as possible.
index.html:
<html>
<head></head>
<body>
<script type="text/javascript" src="test.js"></script>
<form id="myForm" onsubmit="log(this.id)">
<input name="id">
</form>
</body>
</html>
test.js:
function log(str){
console.log("str=" + str);
}
When I submit the form, I see this:
str=[object HTMLInputElement]
and when I change the value of name to anything but "id", I see the expected
str=myForm
I get the exact same behavior if I switch all instances of "name" and "id"
in the code. In other words, it doesn't seem to be a particular limitation
of either attribute, but something more general.
I'm running MAMP on OS X 10.8; experiencing problem in Firefox 22.0 and
Chrome ver. 28.
Thanks in advance

No comments:

Post a Comment