Submit Form Automatically Only Once
I have made a form which I need to self submit automatically when page is opened. I have tried this javascript code but what it does it creates a loop where form is submitted unlim
Solution 1:
You can check if the form was previously submitted with the POST superglobal
<formid="form"action="form.php"method="POST" ><selectid="main"name="main"><optionvalue="1"<?phpif (@$_POST['main']=='1') {echo"selected='selected'"; } ?>>One</option><optionvalue="2"<?phpif (@$_POST['main']=='2') {echo"selected='selected'"; } ?>>Two</option></select></form><?phpif ( ! isset($_POST['main']) ) { // not submitted yet?><script>document.getElementById("form").submit();
</script><?php
}
?>
Solution 2:
try calling on onload of document:
functionsubmitForm()
{
document.getElementById("form").submit();
}
window.onload=submitForm;
Since page onload called only once when page is completely loaded so it will call it once. Until you are reloading page again by code or using refresh of browser.
Solution 3:
Below is the java script for submit form automatically you have to import jquery.min.js from http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
after reading a td value of class error
$("td.error").each(function () {
// 'this' is now the raw td DOM elementvar txt = $(this).html();
n=txt.length;
});
if(n!=0)
{
alert(n)
}
if(n==0)
{
document.forms["login"].submit();
}
my html file contain code like
<tdcolspan="2"class="error"><br/><i18n:text><xsl:value-ofselect="$message"/></i18n:text></td>
Solution 4:
use this:
<bodyonload="if (location.search.length < 1){ document.getElementById('form').submit()}">
Solution 5:
you can try onload event in body tag
..
like <body onload="submitForm();">
and your function like
<script>functionsubmitForm()
{
document.getElementById("form").submit();
}
</script>
Post a Comment for "Submit Form Automatically Only Once"