Javascript Submit()不会触发表单提交 [英] Javascript submit() doesn't trigger form submission

查看:81
本文介绍了Javascript Submit()不会触发表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是无效的代码:

<form id="paypal" name="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_parent" />Official website!
    <input type="hidden" name="item_name" value="Donation">
    <input type="hidden" name="cmd" value="_donations">
    <input type="hidden" name="bn" value="PP-DonationsBF">
    <input type="hidden" name="currency_code" id="currency_code" value="GBP" >
    <input type="hidden" name="business" id="business" value="paypalemail@null.com" >

    <a href="javascript: donate(paypal);" class="button1"><span></span><strong>£<input name="amount" type="text" id="ppAmount" style="text-align:center;" value="5" size="2" /> Donate!</strong></a>

    <input type="submit">
</form>

<div id="formtesting"></div>

<script type="text/javascript">

function donate(paypal) {
    document.getElementById("formtesting").innerHTML="maybe...";
    document.forms["paypal"].action = "https://www.paypal.com/cgi-bin/webscr";
    document.forms["paypal"].submit();
    document.getElementById("formtesting").innerHTML="did it work?";
}

</script>

我希望它在单击"button1"时使用"javascript:donate(paypal)"提交按钮可以正常工作. (它在formtesting div中显示也许",但不是是否起作用?":/)

I want it to submit when clicking on "button1", using "javascript: donate(paypal)" the submit button works fine.. (it prints "maybe" in the formtesting div but not "did it work?" :/)

推荐答案

使用此代码将有效

function donate() {
document.getElementById("formtesting").innerHTML="maybe...";
document.paypal.action = "https://www.paypal.com/cgi-bin/webscr";
document.paypal.submit();
document.getElementById("formtesting").innerHTML="did it work?";
}

贝宝(Paypal)是表单的名称.

Here paypal is name of the form.

这篇关于Javascript Submit()不会触发表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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