将表单重置为Null或重新加载页面usign重置即使提交后也是如此 [英] Reset the form to Null or Reload the page usign reset even after a submit

查看:93
本文介绍了将表单重置为Null或重新加载页面usign重置即使提交后也是如此的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


这就是场景:


我有两个按钮 - 提交和重置

提交用于验证,验证通过后,将其传递给另一个表单进入数据库。


基本上,如果在使用表单中的提交按钮之前使用它,重置工作正常。例如,如果提交时存在一些错误,因为值未通过验证。显示错误弹出消息,并且值保留在字段中。现在,如果我使用重置,则字段的所有值都不会返回null。


我是表格验证新手。我在网上查了一下,它表示如果我们使用了提交,重置将无法清除,我们需要使用javascript来执行此操作。


所以我重置为一个按钮,onclick事件调用reset()函数并清除表单,但我确信代码不对,因为它不工作,我累了在我的功能中发出一条警告信息,以重新启动函数被调用,但我认为不是。


发布我的代码


[代码]


< INPUT id = reset1 name = reset1 type = button value =重置onClick =" reset()">


< Script>

function reset()

{

alert(所有值现在应清除);


document.frmUser.name ="" ;

document.frmUser.user ="" ;

document.frmUser.contactNumber ="" ;;

document.frmUser.email ="" ;


}

< / Script>


我不确定它是否是最好的方法。


我希望每次单击重置时刷新/重新加载整个表单,并且所有字段都没有值。


感谢您的帮助。


Sree

Hi everyone,

This is the scenario:

I have two button - Submit and Reset

Submit is used for validation and after validation is passed it passes it to another form to enter into database.

Bascially the reset works fine if I use it before using the submit button in the form. For instance,if on submit there is some error as the values have not passed a validation. There is a error pop up message shown and the values are retained in the field and Now if I use reset , all the values of the field do not go back to null.

I am new with form validation. I checked online and it said that reset will not clear if we have used submit and we need to use javascript to do it.

So I made reset into a button which onclick event calls the reset() function and clears the form but I am sure that the code is not right as it is not working, I tired putting a alert message in my fucntion to reassue that the function is being called but I think it is not.

Posting my code

[code]

<INPUT id=reset1 name=reset1 type =button value=Reset onClick="reset()">

<Script>
function reset()
{
alert ("all values shall be cleared now");

document.frmUser.name = "" ;
document.frmUser.user = "" ;
document.frmUser.contactNumber = "";
document.frmUser.email = "" ;

}
</Script>

I am not sure if its the best way to do it.

I want the whole form to refresh/ reload everytime reset is clicked and all the fields to have no values.

Thanks for the help in advance.

Sree

推荐答案

我可能听说过这个,或者可能是其他的东西但是......


你用什么语言写网页? HTML,PHP,ASP.NET?
i might have heard about this, or maybe its somethings else but..

what language are u using to write the webpage? HTML, PHP, ASP.NET?



i可能听说过这个,或者可能是其他东西但是......


你用什么语言写网页? HTML,PHP,ASP.NET?
i might have heard about this, or maybe its somethings else but..

what language are u using to write the webpage? HTML, PHP, ASP.NET?



我正在使用ASP页面。我只是想在单击重置时将所有字段值设置为null。 Javascript教程提到了重置值,但我的IE浏览器说,不支持这个对象。所以我可能要将所有值都设置为null ???我不确定,实际上很困惑:D

I am using ASP page. Its just I want to set all the field values to null when we click reset. Javascript tutorials mention usign reset value but my IE browser says, does not support this object. So I may have to set all the values back to null??? I am nto sure, actually confused :D


就像表格有一个submit()函数一样,它们有一个reset()函数。你不必自己制作。

Just like forms have a submit() function, they have a reset() function. You don''t have to make your own.

展开 | 选择 | Wrap | 行号


这篇关于将表单重置为Null或重新加载页面usign重置即使提交后也是如此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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