yosii Posted February 16, 2013 Share Posted February 16, 2013 <html> <head> <script> document.getElementById('a1').submit() </script> </head> <body> <form name="a1" action="5.php" method="post" > <INPUT TYPE="hidden" value="111111" NAME="name" > <INPUT TYPE="hidden" value="22222" NAME="add" > </form> </body> </html> why it is not work? Link to comment https://forums.phpfreaks.com/topic/274570-auto-submit-not-work/ Share on other sites More sharing options...
yosii Posted February 16, 2013 Author Share Posted February 16, 2013 or like this <html> <head> <script> document.getElementById('a1').submit() </script> </head> <body> <form id="a1" action="5.php" method="post" > <INPUT TYPE="hidden" value="111111" NAME="name" > <INPUT TYPE="hidden" value="22222" NAME="add" > </form> </body> </html> not work Link to comment https://forums.phpfreaks.com/topic/274570-auto-submit-not-work/#findComment-1412809 Share on other sites More sharing options...
kicken Posted February 16, 2013 Share Posted February 16, 2013 Because at the point when your script executes, your form does not exist yet. You need to move the script after the form, or change it to run onload. Link to comment https://forums.phpfreaks.com/topic/274570-auto-submit-not-work/#findComment-1412814 Share on other sites More sharing options...
codefossa Posted February 18, 2013 Share Posted February 18, 2013 As said above, you need to wait for the page to load, then execute the code. Here's three ways to do so. window.addEventListener("load", function() { // Code Goes Here }, false); function ready() { // Code Goes Here } window.addEventListener("load", ready, false); function ready() { // Code Goes Here } window.onload = ready; Link to comment https://forums.phpfreaks.com/topic/274570-auto-submit-not-work/#findComment-1413047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.