javascript - Can't submit button on load event -
i created example work jquery 1.7.2 , onload event click onload event nobody needs click.
here example:http://jsfiddle.net/fztd5/32/
<script> window.onload=function(){ document.getelementbyid("formbutton").submit(); } </script> <form action="page/site" method="post"> <input type="hidden" name="name" value="value" /> <input type="submit" id="formbutton" /> </form>
i tried
document.getelementbyid("formbutton").click();
please can me?
you have 2 mistakes: 1- form's method 'postt' , submit's invocation on button instead form element. try this
<script type="text/javascript"> $(document).ready(function(){ $("#form").submit() }) </script> <form action="page/site" method="post" id="form"> <input type="hidden" name="name" value="value" /> <input type="submit" id="formbutton" /> </form>
edited:
if redirect same page , want avoid endless submit loop, try
<script type="text/javascript"> $(document).ready(function(){ if (window.location.search.indexof("auto_submited") == -1){ $("#form").attr('action', $("#form").attr('action') + "?auto_submited=1") $("#form").submit() } }) </script> <form action="page/site" method="post" id="form"> <input type="hidden" name="name" value="value" /> <input type="submit" id="formbutton" /> </form>
it's better check in server-side, being possible javascript
Comments
Post a Comment