Sperr
Sperr

Reputation: 599

JQuery form submit not sending post

I am having trouble submitting a form with JQuery. The form submits correctly when the submit button is pressed, but when I try to use:

$('#somebutton').click(function(){
  $('form#myForm').submit();
});

I've additionally tried calling form submit from the Chrome console.

The form is not submitted correctly - from looking at the chrome inspector, it seems that the post message is never sent. The page is still reloaded, but seemingly without the changes that would be from the post data being sent.

Here's the form:

<form id="myForm" enctype="multipart/form-data" method="POST">
  <input id="firstOption" type="radio" name="radioSelection" value="1" />
  <input id="secondOption" type="radio" name="radioSelection" value="2" />
  <input type="button" name="submitbtn" value="Submit" title="Submit" />
</form>

I am using JQuery v1.7.1.

Upvotes: 2

Views: 6513

Answers (3)

sahbeewah
sahbeewah

Reputation: 2690

If you press the submit button, the submitButton name/value pair is also passed along with the form data, which is different to if you submit it programatically. This may cause the back-end to think that the POST was not submitted properly (depending on the implementation).

Upvotes: 4

Popsyjunior
Popsyjunior

Reputation: 305

here's your html:

<form id="myForm" enctype="multipart/form-data" method="POST">
  <input id="firstOption" type="radio" name="firstOption" value="1" />
  <input id="secondOption" type="radio" name="secondOption" value="2" />
  <input type="button" name="submitbtn" value="Submit" title="Submit" />
</form>

And here's your jquery:

<script type='text/javascript'>
  $(function(){
    $("#myForm").submit(); 
  });
</script>

Cheers..!!

Upvotes: 0

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

You have not defined the action page:

<form action="your_page.html" id="myForm" enctype="multipart/form-data" method="POST">

Upvotes: 2

Related Questions