1

I know that using $('form').submit() does not work when the submit button is named with the reserved name "submit".

The annoying thing is that I can't change the html of the form that I want to submit.

I thought a workaround would be to delete the input button before using $('form').submit(), but that doesn't seem to work.

$('input:last').remove();
$('form').submit();

Does anybody know another solution for this problem?

OO-SKY
  • 91
  • 1
  • 12
  • doesn't the form have an id or class or something like that? – Mathlight Oct 12 '12 at 06:54
  • or try `$('form[0]').submit();` and the number must correspond to the number of the form counting from start of the body – Mathlight Oct 12 '12 at 06:57
  • The form doesn't have an id or a class. But selecting the elements with my code does work. Manually removing the submit button in the html code is the solution for my problem, but when I try to do this using javascript the problem still exists. – OO-SKY Oct 12 '12 at 07:05
  • alright, look at the comment i gave in the answer of NullPointer... mayby that helps – Mathlight Oct 12 '12 at 07:06

2 Answers2

3

You have two choices:

1.Create a formElement and use its .submit methods.

document.createElement('form').submit.apply($('form')[0]);

2.Use the .submit method form the prototype of HTMLFormElement

HTMLFormElement.prototype.submit.apply($('form')[0]);

The reason is stated in this answer.

Community
  • 1
  • 1
xdazz
  • 158,678
  • 38
  • 247
  • 274
0

Here is the sample code i used once. It should work for you too.

<form method="post" action="" id="myform">
<input type="text" value="kdfhdjskfsdhf" name="test" />
<input type="button" name="submit" value="submit" onclick="submit_this_form()" />
</form>

function submit_this_form(){
    jQuery($('input[name="submit"]')).attr('name', 'new_submit');
    jQuery('#myform').submit();
}