How to submit an HTML form when loading a page?

How to submit this form without submit button. I want to submit it when downloading this form,

<form name="frm1" id="frm1" action="../somePage" method="post"> Please Waite... <input type="hidden" name="uname" id="uname" value="<?php echo $uname;?>" /> <input type="hidden" name="price" id="price" value="<?php echo $price;?>" /> </form> 
+4
source share
6 answers

Do it:

 $(document).ready(function(){ $("#frm1").submit(); }); 
+4
source

You do not need jQuery here! simplest solution here (based on answer from charles):

 <html> <body onload="document.frm1.submit()"> <form action="http://www.google.com" name="frm1"> <input type="hidden" name="q" value="Hello world" /> </form> </body> </html> 
+31
source

You can also try using below script

 <html> <head> <script> function load() { document.frm1.submit() } </script> </head> <body onload="load()"> <form action="http://www.google.com" id="frm1" name="frm1"> <input type="text" value="" /> </form> </body> </html> 
+7
source

You can do this using simple single-line JavaScript code, and also be careful if JavaScript is turned off, this will not work. The code below will do the job if JavaScript is disabled.

Turn off JavaScript and run the code in your own file to find out its full function. (If you disable JavaScript here, the code snippet below will not work)

 .noscript-error { color: red; } 
 <body onload="document.getElementById('payment-form').submit();"> <div align="center"> <h1> Please Waite... You Will be Redirected Shortly<br/> Don't Refresh or Press Back </h1> </div> <form method='post' action='acction.php' id='payment-form'> <input type='hidden' name='field-name' value='field-value'> <input type='hidden' name='field-name2' value='field-value2'> <noscript> <div align="center" class="noscript-error">Sorry, your browser does not support JavaScript!. <br>Kindly submit it manually <input type='submit' value='Submit Now' /> </div> </noscript> </form> </body> 
+4
source

You missed the closing tag for input fields, and you can select any of the events, for example: onload, onclick, etc.

(a) Onload event:

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

(b) Onclick Event:

 <form name="frm1" id="frm1" action="../somePage" method="post"> Please Waite... <input type="hidden" name="uname" id="uname" value=<?php echo $uname;?> /> <input type="hidden" name="price" id="price" value=<?php echo $price;?> /> <input type="text" name="submit" id="submit" value="submit"> </form> <script type="text/javascript"> $('#submit').click(function(){ $('#frm1').submit(); }); </script> 
+3
source

using javascript

  <form id="frm1" action="file.php"></form> <script>document.getElementById('frm1').submit();</script> 
+3
source

All Articles