2013-07-23 81 views
0

背景html页面自动提交 - JavaScript的填充隐藏字段

当加载页面时,会出现付款按钮,点击按钮后付费将触发表单提交(这一点)的javascript方法调用。

当提交按钮被点击时,它会调用return pay(this),这会填充更多隐藏的字段,然后提交给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> 

问题 如何使页面调用“的onsubmit =”返回薪酬(本)”时自动加载页面,然后再提交reponse.php?

我试图把下面的代码在HTML文件的末尾。

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

这并不正确行动,这似乎是“买单(本)”没有得到正确加载。

回答

2

这应该工作

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

这将触发由提交事件触发功能,以及在表单上的提交事件的出现。

+0

.submit()不会调用“return pay(this)”,我该怎么做? – handicop

+0

是onsubmit的错误用法。相反,请在

标记上添加onsubmit事件,如这应该起作用。 –