Karem
Karem

Reputation: 18103

JS: Posting form directly

If on document.ready, I want my form to auto post itself, is this possible?

So when the document has loaded, then it posts itself and takes to the action="" (in this case is ?upload=true).

I heard about $.post() jquery, but this is just for posting in the background?

Upvotes: 0

Views: 69

Answers (3)

Brian Donovan
Brian Donovan

Reputation: 8390

You want something like this:

$(function() {
  $('#myformid').submit();
});

See the documentation for jQuery's submit().

And see this working demo: http://jsfiddle.net/8hg8s/

Upvotes: 0

Peter Bailey
Peter Bailey

Reputation: 105868

Yes, $.post() in jQuery is for POST requests with AJAX.

If you want a form to submit on the document ready event, just invoke the submit itself!

$(document).ready( function()
{
  $('form').submit()
});

Upvotes: 1

RhinoDevX64
RhinoDevX64

Reputation: 707

$.post() is an AJAX call and will not force the entire page to postback.

you may want to try

$(document).ready(function(){
     var form = $("#yourformid");
     form.submit();
});

Upvotes: 3

Related Questions