如果未输入必填字段,则显示表单单击提交按钮的错误消息。在错误消息中显示未填充的字段名称 [英] To display error message for a form onclick of submit button if mandatory fields not entered..appending the unfilled field names in error message

查看:148
本文介绍了如果未输入必填字段,则显示表单单击提交按钮的错误消息。在错误消息中显示未填充的字段名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个表格,其中某些字段需要强制填写。

如果用户没有填写任务,请单击提交按钮错误消息弹出。

错误消息的默认文本为:在提交此表单之前,请确保完成以下必填字段:

以及未填充的字段名称将作为错误消息附加。

以下是我尝试的逻辑..

但它似乎没有工作....任何人都可以建议我即兴创作吗?







函数ExitForm(){

var msg ='' '';

var elem = document.form.elements;

var flag = 0;

//

条件检查字段是否已填满。如果不是,

msg + =\ n+text1







用于textfields,textareas,radiobutton,dropdownlist

//



for(i = 0; i< = elem.length; i ++){



var ele = elem [i];



if(ele .type ==text|| ele.type ==radio|| ele.type ==textarea|| ele.type ==select){



if(((ele.value == null)||(ele.value ==))|| isBlank(ele.value)){



flag = 1;



}

}

}

if(flag == 1)

{

alert(在提交此表单之前,请确保完成以下必填字段:+ msg);

}



}

Hi,
I have a form with certain fields to be filled in mandatorily.
If user doesn''t fill mandates,onclick of submit button error message has to popup.
The error message has default text as : "Before submitting this form,make sure the following mandatory fields are completed:"
along with this the unfilled field names will be appended as error msg.
Following is the logic i tried..
But it doesnt seem to work....Can anyone please suggest me to improvise it?



function ExitForm(){
var msg = '''';
var elem = document.form.elements;
var flag = 0;
//
condition to check if a field is filled. If no,
msg+= "\n"+"text1"
.
.
.
for textfields,textareas,radiobutton,dropdownlist
//

for(i=0;i<=elem.length;i++){

var ele = elem[i];

if(ele.type == "text" || ele.type == "radio" || ele.type == "textarea" || ele.type == "select"){

if ( ((ele.value == null) || (ele.value == "")) || isBlank(ele.value)){

flag = 1;

}
}
}
if (flag == 1)
{
alert("Before submitting this form,make sure the following mandatory fields are completed:"+msg);
}

}

推荐答案

hi,



查看此



HT tp://msdn.microsoft.com/en-us/library/e78xxk8k%28v=vs.71%29.aspx [ ^ ]


hi,



使用这个



ASP.NET中的自定义验证摘要 [ ^ ]


这篇关于如果未输入必填字段,则显示表单单击提交按钮的错误消息。在错误消息中显示未填充的字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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