如何使用JavaScript提交表单? [英] How can I submit a form using JavaScript?

查看:51
本文介绍了如何使用JavaScript提交表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ID为theForm的表单,该表单具有以下div,其中包含一个提交按钮:

I have a form with id theForm which has the following div with a submit button inside:

<div id="placeOrder"
     style="text-align: right; width: 100%; background-color: white;">
    <button type="submit"
            class='input_submit'
            style="margin-right: 15px;"
            onClick="placeOrder()">Place Order
    </button>
</div>

单击时,将调用功能placeOrder().该函数将上述div的innerHTML更改为"processing ...". (因此,提交按钮现在消失了.)

When clicked, the function placeOrder() is called. The function changes the innerHTML of the above div to be "processing ..." (so the submit button is now gone).

上面的代码有效,但是现在的问题是我无法提交表单!我尝试将其放在placeOrder()函数中:

The above code works, but now the problem is that I can't get the form to submit! I've tried putting this in the placeOrder() function:

document.theForm.submit();

但这不起作用.

如何获取表格?

推荐答案

将表单的name属性设置为"theForm",您的代码将起作用.

Set the name attribute of your form to "theForm" and your code will work.

这篇关于如何使用JavaScript提交表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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