html页面自动提交-javascript填充隐藏字段

html page submit automatically - javascript fills hidden field

本文关键字:-javascript 填充 隐藏 字段 提交 html      更新时间:2023-09-26

背景

当页面加载时,会有付款按钮,点击按钮后会触发表单提交付款(此)javascript方法调用。

当点击提交按钮时,它将调用return pay(this),它将填充更多隐藏字段,然后提交到response.hp.

<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>

问题当页面加载并提交reponse.php时,我如何使页面自动调用"onSubmit="return pay(this)"?

我试着把下面的代码放在html文件的末尾。

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

这不正确,似乎"pay(This)"没有正确加载。

这应该能在中工作

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

这将通过触发提交事件中的函数来触发表单上的提交事件。