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>
This question is related to
php
javascript
html
jquery
using javascript
<form id="frm1" action="file.php"></form>
<script>document.getElementById('frm1').submit();</script>
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>
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>
You missed the closing tag for the input fields, and you can choose any one of the events, ex: 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>
You can do it by using simple one line JavaScript code and also be careful that if JavaScript is turned off it will not work. The below code will do it's job if JavaScript is turned off.
Turn off JavaScript and run the code on you own file to know it's full function.(If you turn off JavaScript here, the below Code Snippet will not work)
.noscript-error {_x000D_
color: red;_x000D_
}
_x000D_
<body onload="document.getElementById('payment-form').submit();">_x000D_
_x000D_
<div align="center">_x000D_
<h1>_x000D_
Please Waite... You Will be Redirected Shortly<br/>_x000D_
Don't Refresh or Press Back _x000D_
</h1>_x000D_
</div>_x000D_
_x000D_
<form method='post' action='acction.php' id='payment-form'>_x000D_
<input type='hidden' name='field-name' value='field-value'>_x000D_
<input type='hidden' name='field-name2' value='field-value2'>_x000D_
<noscript>_x000D_
<div align="center" class="noscript-error">Sorry, your browser does not support JavaScript!._x000D_
<br>Kindly submit it manually_x000D_
<input type='submit' value='Submit Now' />_x000D_
</div>_x000D_
</noscript>_x000D_
</form>_x000D_
_x000D_
</body>
_x000D_
Source: Stackoverflow.com