表格提交 [英] form submission

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

问题描述

我有这样的表单:

 < form id =basicTermsmethod =postonsubmit =return validateForm ()> 

以及 onsubmit 中的函数如下:

 函数validateForm()
{
return false;
}

我这样做是为了测试表单,当我点击Enter或点击表单上的一个按钮,触发表单提交动作,表单提交并移动到下一页。



我也有这些按钮的形式:

 < tr> 
< td align =left>< button style =background-color:#FF80FFonclick =javascript:document.getElementById('basicTerms').action ='helpFile1.php'; document .getElementById('basicTerms')。submit()tabindex =6>返回< /按钮>< / td>
< td align =center>< button style =background-color:#FFC080onclick =javascript:document.getElementById('basicTerms').action ='helpFile2.php'; document .getElementById('basicTerms')。submit()tabindex =4>让我们转到步骤2< / button>< / td5>
< td align =right>< button style =background-color:#00FF00onclick =printThis()tabindex =5>列印< / button>< / td> ;
< / tr>

我想知道为什么表单会提交,即使我在 onsubmit



我已经在Google Chrome和FireFox上测试了这个表单,两者都给出了相同的结果。另外,我正在测试localhost WAMP:Apache2.2.11,PHP5.3.0。 尝试添加 type =button到你的按钮标签。否则,我相信他们默认提交按钮。



(作为答案添加,因为它作为解决方案)

I have this form:

<form id="basicTerms" method="post" onsubmit="return validateForm()">

and the function in the onsubmit is below:

function validateForm()
{
    return false;
}

I've done this to test the form, and when I click Enter or click on a button on the form that performs triggers the form submit action, the form submits and moves to the next page.

I also have these buttons in the form:

<tr>
    <td align="left"><button style="background-color:#FF80FF" onclick="javascript:document.getElementById('basicTerms').action='helpFile1.php'; document.getElementById('basicTerms').submit()" tabindex="6">Go Back</button></td>
    <td align="center"><button style="background-color:#FFC080" onclick="javascript:document.getElementById('basicTerms').action='helpFile2.php'; document.getElementById('basicTerms').submit()" tabindex="4">Lets Go To Step 2</button></td5>
    <td align="right"><button style="background-color:#00FF00" onclick="printThis()" tabindex="5">Print</button></td>
</tr>

I want to know why the forms submits even when I return a false in onsubmit.

I've tested the form on Google Chrome and FireFox, both gave the same result. Also, I'm testing on localhost WAMP: Apache2.2.11, PHP5.3.0.

解决方案

Try adding type="button" to your button tags. Otherwise I believe they default to submit buttons.

(added as an answer since it worked as a solution)

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

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