表单验证仍允许提交空字段 [英] Form validation still allows submission of empty fields

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

问题描述

嗨..伙计们

我试图用JavaScript来验证我的HTML空字段。我的代码如下。问题是我可以逃避验证并提交空字段。


任何线索?

Hi.. guys
I?m trying to use JavaScript to validate my HTML for empty fields. My code is as below. The problem is that I can escape validation and submit empty fields.

Any clue?

展开 | 选择 | Wrap | 行号

推荐答案


嗨..伙计们

我试图用JavaScript来验证我的HTML对于空的领域。我的代码如下。问题是我可以逃避验证并提交空字段。


任何线索?


< html>

< head>

< script language =" JavaScript">

函数isEmpty(inputStr,fieldname){

if (inputStr == null || inputStr ==""){

alert(请填写方框)

document.form1.fieldname.focus ();

document.form1.fieldname.select();

返回false;

} else {

返回true;

}


}

< / script> < / head>

< body>

< form name =" form1"方法= QUOT; GET" action = ???????????>

< p>用户ID:

< input type =" text"名称= QUOT; TXT1"的onblur = QUOT;的isEmpty(txt1.value,txt1.name)QUOT; />

< br />

< p>用户名:

< input type =" text"名称= QUOT; TXT2" onBlur =" isEmpty(txt2.value,txt2.name)" />

< br /> < br />

< input type =" submit" VALUE = [提交" />

< / form> < /体> < / HTML>
Hi.. guys
I?m trying to use JavaScript to validate my HTML for empty fields. My code is as below. The problem is that I can escape validation and submit empty fields.

Any clue?

<html>
<head>
<script language="JavaScript">
function isEmpty(inputStr,fieldname){
if (inputStr==null || inputStr==""){
alert("please fill in the box")
document.form1.fieldname.focus();
document.form1.fieldname.select();
return false;
} else {
return true;
}

}
</script> </head>
<body>
<form name="form1" method="GET" action=???????????>
<p> User ID:
<input type="text" name="txt1" onBlur="isEmpty(txt1.value,txt1.name)"/>
<br />
<p> User Name:
<input type="text" name="txt2" onBlur="isEmpty(txt2.value,txt2.name)"/>
<br /> <br />
<input type="submit" VALUE="SUBMIT" />
</form> </body> </html>



你错了

路径在行动= ???????????

像这个动作一样使用=""。


Akhilesh

You had given wrong
path in action=???????????
use like this action="".

Akhilesh


Thanx

问题不在于action属性,你可以消除它。问题是如何防止提交空字段。 (得到了吗?)

干杯
Thanx
The problem is not because of the action attribute, you may eliminate it. The issue is how to prevent of submission empty fields. (got it?)
Cheers

你错了

路径在行动= ???? ???????

像这个动作一样使用=""。


Akhilesh
You had given wrong
path in action=???????????
use like this action="".

Akhilesh


而不是传递名称,传递对象本身,例如txt1中。然后在你的函数中,代替
Instead of passing the name, pass the object itself, e.g. txt1. Then in your function, in place of
展开 | 选择 < span class =codeDivider> | Wrap | 行号


这篇关于表单验证仍允许提交空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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