如何使用javascript提交表单? [英] How to submit a form using javascript?

查看:111
本文介绍了如何使用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();

但这不起作用。

我如何才能提交表格?

推荐答案

设置名称您的表单属性为theForm,您的代码将有效。

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

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

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