Helping ordinary people create extraordinary websites!
   

How can I automatically submit a form using JavaScript?

Monday, 24th August 2009
by Stevo


I want to automatically submit a form in the background when a specific page is loaded. It should be type of onload event but I cant seem to get it working.



Texas
Hey Stevo,

This should do the trick

<form action="page_to_post_to.php" method="post" id="autopostform">
<!-- form content -->
</form>

<script type="text/javascript">

function autopost() {

var morf = document.getElementById("autopostform"); morf.submit();

} window.onload = autopost;

</script>
Tuesday, 25th August 2009
Votes:
24
15

More JavaScript Help:
» How to use Javascript to produce a dynamic population clock?
» How can I resize a window to a specific size using JavaScript?
» How to create an online voting or survey system using JavaScript?
» How to limit in real-time the number of characters in textarea with JavaScript?
» How can I disable my submit button if the textarea in my form is empty?
» JavaScript random number?
» How can I do a for loop in JavaScript?
» Catching up events outside an iframe