拥有表单验证程序,并希望获得以下两个输入字段的常见错误消息。这可能吗:
<select id="category" name="category" onchange="showSelected1();" style="width:160px">
<option value="00"><font color="#999999">Category</font></option>
<option value="1">Marriages</option>
<option value="2">Birthdays</option>
</select>
<select id="city" name="city" onchange="showSelected();" style="width:160px">
<option value="000"><font color="#999999">City</font></option>
<option value="1">New York</option>
<option value="2">Washington</option>
</select>
并使用了gen_validatorv4.js。
var frmvalidator= new Validator("frm1");
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("category","dontselect=00","Select Category");
frmvalidator.addValidation("city","dontselect=000","Select City");
想要收到错误消息,例如&#34;选择类别和城市&#34;。 (两者只有一条错误消息)
答案 0 :(得分:0)
根据此URL,您可以使用gen_validatorv4.js构建自定义验证函数: http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
所以尝试这样的事情:
function DoCustomValidation() {
if (document.getElementById('category').value == "00" || document.getElementById('city').value == "000") {
var element;
if (document.getElementById('category').value == "00") {
element = document.getElementById('category');
}
else {
element = document.getElementById('city');
}
sfm_show_error_msg("Select category and city", element);
return false;
}
else {
return true;
}
}
frmvalidator.setAddnlValidationFunction("DoCustomValidation");