Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to submit an HTML form on loading the page?

How to submit this form without using submit button. I want to submit it in loading 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>
like image 969
Vinod VT Avatar asked Mar 05 '13 04:03

Vinod VT


People also ask

How to submit form automatically on page load in JavaScript?

After that add onload event to body. How to Submit Form Automatically On Page Load In JavaScript Below JavaScript code helps to submit form on load instead of clicking submit button. Use the Form name exactly, as it is used in the HTML page. XHTML <script language="javascript"> function onLoadSubmit() { document.nameofForm.submit(); } </script>

How do you submit a form in HTML?

The Submit Button The <input type="submit"> defines a button for submitting the form data to a form-handler. The form-handler is typically a file on the server with a script for processing input data.

How to prevent the page from reloading when form is submitted?

When this html form is submitted, it will call the javascript function yourJsFunction (), but it won’t reload the page. 2. Use jQuery’s submit event to handle the form submit, add return false; at the end of the submit handle function to prevent the page to reload.

How to submit form on load instead of clicking submit button?

Below JavaScript code helps to submit form on load instead of clicking submit button. Use the Form name exactly, as it is used in the HTML page. Add this onload function to body tag, we are executing onLoadSubmit function on page load. If you are not using this function, then this code won’t work. <body onload="onLoadSubmit ()"> <!--


2 Answers

You don't need Jquery here! The simplest solution here is (based on the 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>
like image 193
HNygard Avatar answered Sep 20 '22 06:09

HNygard


You can try also 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> 
like image 25
charles Avatar answered Sep 24 '22 06:09

charles