简体   繁体   中英

html page submit automatically - javascript fills hidden field

Background

When the page is loaded, there will be payment button, click on the button will fire the form submission after pay(this) javascript method call.

When submit button is clicked, it will call return pay(this), which will fill more hidden fields and then submit to response.php.

<form id=ini method=post action="response.php" onSubmit="return pay(this)">
..
..
hidden fields - some of them are filled with value from get values of the previous page
..
..
<input type=submit>
</form>

Question How do I make the page to call "onSubmit="return pay(this)" automatically when the page is loaded and then submitted reponse.php?

I tried to put the below code at the end of html file.

<script type='text/javascript'>
document.ini.submit();
</script>

This does not act correctly, it seems like "pay(this)" didn't get loaded correctly.

This should work

<script> 
window.onload=function(){ 
       document.getElementById('ini').submit(); 
} 
</script>

This will trigger a submit event on the form there by triggering the function in the submit event as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM