一键提交两份表格 [英] Submit two forms with one button

查看:24
本文介绍了一键提交两份表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种 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:

If your forms have IDs:

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆