[英]javascript multiple message form validation
I m using a jquery system in order to validate input in an html form. 我正在使用jquery系统以验证html形式的输入。 In the email field I want to display either validate[required] or custom[email] that represent 2 error messages (but not both).
在电子邮件字段中,我要显示代表2条错误消息(但不能同时显示)的validate [必需]或custom [email]。 Im not too skilled in Javascript but here's my attempt
我不太会使用Java语言,但这是我的尝试
<form id="formID1" action="report-problem.asp" name="varsForm1" method="post">
<script language="Javascript">...
function IsEmpty(){
var class = "";
if(document.forms['formID1'].email1.value == "")
{
class='validate[required]';
}
else
{
class= 'validate[custom[email]]';
}
return class;
}
</script>
<td>Email Address</td>
<td class="input" width="302"><input name="email1" type="text" id="email1" class="IsEmpty();" value="" /></td>....
<input name="" id="submitbtn" type="submit" value="Send" />
if(document.forms['formID1'].email1.value == "")
{
$("#email1").removeClass('validate[custom[email]]');
class='validate[required]';
}
else
{
$("#email1").removeClass('validate[required]');
class= 'validate[custom[email]]';
}
return class;
You should remove previous class when you adding new error class in your email field. 在电子邮件字段中添加新的错误类别时,应删除先前的类别。 It should Work :)
它应该工作:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.