I just found that I can use $('form').prop(name)
to get input with that name within the form. Then I experimented on other tags, and this won't work for div
and body
. Now I don't have a way to tell if a form needs to post
or get
if there is an input named method
, which unfortunately is true in one of my pages.
Bonus: I can't get action
of a form if there is an input named action
inside it, either.
<!doctype html>
<html lang="en">
<head>
<title>jQuery.prop()</title>
<script src="../../jquery-1.9.1.js"></script>
<script>
$(function() {
var method = $('form').prop('method');
console.log(method); // <select> element
var form = $('form')[0];
console.log(form.method); // <select> element
$('form').prop('method', 'get');
console.log(form.method); // still <select> element, but DOM inspector shows the form method is changed to "get"
form.method='get';
console.log(form.method); // still <select> element
});
</script>
</head>
<body>
<form action="/Test/Create" method="post">
<input type="text" name="content" value="" />
<select name="method">
<option value="phone">Phone</option>
<option value="email">Email</option>
</select>
</form>
</body>
</html>
So, how do I get form.method (or action) when there is an input with that name inside it?