See http://jsfiddle.net/8KNc7/5/ for a working example of what I am talking about (testing in Firefox 15 right now, haven't tried others).
I have a form with a submit
input and a button
input that both submit the form data to the server, but only the submit
input causes the jQuery submit event to run. Why is this?
Form:
<form action='/echo/html/' method='post' id='Form' name='Form'>
<input type='hidden' value='posted' id='html' name='html'>
<input type='submit' id='submit1' value='submit type'>
<input type='button' id='submit2' value='button type' onclick='submitForm();'>
</form>
Javascript (running at the end of the body tag):
var theForm = document.forms['Form'];
if (!theForm) {
theForm
= document.Form;
}
function submitForm() {
theForm
.submit();
}
$
(function () {
$
('form').submit(function () {
alert
('ok');
});
});
Point is, I am expecting both buttons to cause the alert but only one does. I know I can submit change the
cross posting from stackoverflow: http://stackoverflow.com/questions/12502957/why-doesnt-submitting-a-form-via-the-submit-method-on-the-form-element-invoke
submitForm
function to make it work properly but I am trying to figure out what the difference is in why one of these works and the other does not.
cross posting from stackoverflow: http://stackoverflow.com/questions/12502957/why-doesnt-submitting-a-form-via-the-submit-method-on-the-form-element-invoke