Reputation: 4419
I noticed that the following form can not be submitted by jquery submit() function. The problem seems to be the id of button, which shouldn't be "submit". Why does it work like this?
<script src="jquery.js"></script>
<form action="" id="Foo" method="POST">
<button id="submit" >Bla</button>
</form>
And I called the following line in console:
$('#Foo').submit();
Upvotes: 1
Views: 4222
Reputation: 1672
Updated
Even though it submits already
but if you had to submit manually using jquery you have to use this :
$('#Foo')[0].submit();
as the selection by jquery returns an array of objects related to the dom, the first is the dom itself, so you can submit it this way
Edit:
if you want to prevent it from submitting use this :
$('#submit').onclick(function(event){
event.preventDefault();
});
Edit 2:
If you use the tag <button>
you should always declare the intended type
attribute. In some browsers the default is "submit" while others have the default value of "button".
Upvotes: 4
Reputation: 5105
please change your submit button:
from:
<button id="submit" >Bla</button>
into:
<input class="submit" name="commit" type="submit" value="Bla" />
Upvotes: 1
Reputation: 122026
You should submit with form Id and not with submit button id.
$('#Foo').submit();
Even with Id "submit"
its submitting .
Check fiddle:http://jsfiddle.net/fRUUd/1342/
Upvotes: 0