处理表格 [英] processing a form

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

问题描述

我知道这是愚蠢的,

但是我一直在尝试处理一个表单,同时在

onClick事件中添加一个函数。


我添加onClick事件后,该函数被触发,但

表格不会发布或获取。


有什么帮助吗?

I know this is stupid,
but i''ve been trying to process a form while adding a function to the
onClick event.

as soon as i add the onClick event, the function is triggerred but the
form doesn''t POST or GET.

Any help?

推荐答案

te ******@gmail.com 写道:
te******@gmail.com wrote:
我知道这是愚蠢的,
但我一直在努力处理表格在
onClick事件中添加一个函数。

一旦我添加onClick事件,该函数就被触发但
表单不会发布或获取。

任何帮助?
I know this is stupid,
but i''ve been trying to process a form while adding a function to the
onClick event.

as soon as i add the onClick event, the function is triggerred but the
form doesn''t POST or GET.

Any help?







如果您使用提交按钮,您可以通过2种方式:

1)使用type =" button"而不是type =" submit"

添加一个也提交表单的onClick处理程序。


例如:

< form action =" bla.php" name =" myForm">

firstname:< input type =" text" name =" firstname">

< input type =" button" value ="立即提交 onClick =" checkform();">

< / form>


函数checkform(){

//在这里做点什么

....

//提交它

document.forms.myForm.submit();

}

< / script>

当你可以看出,这个解决方案对于那些因为没有提交表格而被禁用Javascript的人来说有点不友好,因为他们不会提交表格因为

Javascript负责提交。


如果这对您来说是不可接受的,请查看第二个解决方案:


2)在submit-button-element中使用onSubmit()处理程序。 br />

< form action =" bla.php" name =" myForm">

firstname:< input type =" text" name =" firstname">

< input type =" submit" value ="立即提交 onSubmit =" checkform();">

< / form>

在这种情况下,如果禁用javascript,则表单将始终提交。

如果Javascript是ENABLED,函数checkform()可以返回true或false。

重新运行false以防止提交。


此致,

Erwin Moller



Hi,

If you use the submitbutton, you can go 2 ways:
1) Use type="button" instead of type="submit"
Add an onClick handler that also submits the form.

eg:
<form action="bla.php" name="myForm">
firstname: <input type="text" name="firstname">
<input type="button" value="submit now" onClick="checkform();">
</form>

<script type="text/javascript">
function checkform(){
// do something here
....
// submit it
document.forms.myForm.submit();
}
</script>
As you can see, this solution is a little unfriendly for people with
Javascript disabled because they will not submit the form because
Javascript is responsible for the submitting.

If that is unacceptable for you, have a look at the second solution:

2) use onSubmit() handler in the submit-button-element.

<form action="bla.php" name="myForm">
firstname: <input type="text" name="firstname">
<input type="submit" value="submit now" onSubmit="checkform();">
</form>

In this case the form will ALWAYS be submitted if javascript is disabled.
If Javascript is ENABLED the function checkform() can return true or false.
Retrun false to prevent submitting.

Regards,
Erwin Moller


谢谢,


它有效。

还有一个问题,


i使用这个:

< input type =" button"命名= [提交"值= QUOT;发送和QUOT; onclick =" this.disabled

= true;">


点击后,按钮被成功禁用。


我试图制作一个禁用按钮的功能,但它没有工作。

为什么?


Erwin Moller写道:

[...]
Erwin Moller wrote:
[...]
如果你使用提交按钮,你可以去2种方式:
1)使用type =" button"而不是type =" submit"
添加一个也提交表单的onClick处理程序。

[...]

正如你所看到的,这个解决方案对于禁用Javascript的人来说有点不友好,因为他们不会提交表单,因为Javascript负责提交。


这也很不愉快,因为即使启用了脚本,如果

脚本因任何原因失败,表单也不会提交。
<如果这对您来说是不可接受的,请查看第二个解决方案:

2)在submit-button-element中使用onSubmit()处理程序。
If you use the submitbutton, you can go 2 ways:
1) Use type="button" instead of type="submit"
Add an onClick handler that also submits the form.
[...]
As you can see, this solution is a little unfriendly for people with
Javascript disabled because they will not submit the form because
Javascript is responsible for the submitting.
It is also unpleasant because even if scripting is enabled, if the
script fails for any reason, the form will not submit.

If that is unacceptable for you, have a look at the second solution:

2) use onSubmit() handler in the submit-button-element.




这是首选的方法 - 脚本应始终有用,并且

绝不是障碍。


[...]


-

Rob



That is the preferred method - scripting should always be helpful and
never a hindrance.

[...]

--
Rob


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

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