用一个按钮提交两个表单 [英] Submit two forms with one button
本文介绍了用一个按钮提交两个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两种HTML格式,一种是在使用PHP进入数据库时提交数据,另一种是将用户引导至贝宝付款页面,我的问题是用户必须提交两种表格,当然我不会希望他们必须这样做。反正有两种形式使用一个提交按钮吗?
I have HTML two forms, one that submits data upon entry to a database using PHP, the other directs the user to a paypal payment page, my problem is that the user would have to submit both forms which of course I do not want them to have to do. Is there anyway to use one submit button for two forms?
(欢迎使用Javascript)
(Javascript is welcome)
推荐答案
您应该可以使用JavaScript做到这一点:
You should be able to do this with JavaScript:
<input type="button" value="Click Me!" onclick="submitForms()" />
如果您的表单有ID:
submitForms = function(){
document.getElementById("form1").submit();
document.getElementById("form2").submit();
}
如果您的表单没有ID,但有名称:
If your forms don't have IDs but have names:
submitForms = function(){
document.forms["form1"].submit();
document.forms["form2"].submit();
}
这篇关于用一个按钮提交两个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文