Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to automatically execute the "Submit" button. "Window.onload" is not working.

PHP
     <form id="myform" action="../php/e-Moon_Phase.php" method="post">
    <input name="mo1" type="hidden" value="<?php echo $mo; ?>" />
    <input name="dy1" type="hidden" value="<?php echo $dy; ?>" />
    <input name="yr1" type="hidden" value="<?php echo $yr; ?>" />
    <input name="Submit1" type="submit" value="submit" />
</form>
<script type="text/javascript">
        window.onload = function () {
        document.myform.Submit1.click();
        }
    </script>
Posted
Comments
Sergey Alexandrovich Kryukov 23-Aug-14 1:03am    
Execute it 1) by what event? 2) why?
—SA
Mohibur Rashid 23-Aug-14 3:23am    
Why? there is far more better options available, for sure

"Automatically execute" means: sending an HTTP request with the URL defined by the URL written as a value of the attribute action and, in that HTTP request, also send request parameters, in the form "name=value&name=value..." where name and value are the values of the corresponding attributes of the controls present in the form. On the client site, this is done with Ajax: http://en.wikipedia.org/wiki/Ajax_(programming)[^].

A very convenient way to do it is jQuery Ajax: http://api.jquery.com/jquery.ajax[^].

However, I cannot see how your form can make any sense. All the input controls are hidden, and their values are constants. Effectively, this form won't submit any useful data, so, on the server side, you could simply assume this data is always constant, or simply don't use it. However, I'll understand if this is just an incomplete sample, and real HTML will be different.

—SA
 
Share this answer
 
JavaScript
document.myform.Submit1.click();


This is wrong way, i think.

Use like this

JavaScript
document.getElementById("formid").submit();


JavaScript
//use any event here. 

window.onload()=function(){

document.getElementById("formid").submit(); 

}


no
 
Share this answer
 
XML
<script type="text/javascript">

            function redirect1()
            {
                  window.location.assign("test.html")
            }
        </script>

</head>

<body onload="redirect1()">


 <form id="myform" action="test.html" method="post">
        <input name="mo1" type="hidden" />
        <input name="dy1" type="hidden"  />
        <input name="yr1" type="hidden"  />
        <input name="Submit1" type="submit" value="submit" />
    </form>
 
Share this answer
 
<html>
<head>
<script type="text/javascript">
function redirect()
{
window.location.href="Test.html"
}
</script>
</head>
<body onLoad="redirect()">
<form name="my_form" method="get">
<input type="hidden" />
<input type="submit" name="my_sub" />
</form>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900