我有这两个用于验证文本输入字段和下拉选择的 java 函数。我正在尝试结合两个验证 onSubmit。当我将两个验证放在一起时它不起作用,但是当我当时放置一个时它起作用。
function validname(fld) {
var error = "";
var valid = /^[a-zA-Z0-9\-]*$/;
if (fld.value == "") {
fld.style.borderColor = '#ff0000';
document.getElementById('name').style.color = "#ff0000";
error = " - Invalid device name..\n";
} else if(valid.test(fld.value)){
fld.style.borderColor = '';
document.getElementById('name').style.color = "#000000";
} else {
fld.style.borderColor = '#ff0000';
document.getElementById('name').style.color = "#ff0000";
error = " - Invalid device name. \n";
}
return error;
}
function ValidateDropForm() {
var isValidDropForm = true;
var errorMessages = "";
var e = document.getElementById('domain');
if (e.options[e.selectedIndex].text == "--Select--") {
document.getElementById('domainError').innerHTML = "- Domain name required.";
isValidDropForm = false;
}
if (!isValidDropForm) {
//alert(errorMessages);
}
return isValidDropForm;
}
这是我做的..
HTML
<form action="" method="POST" onsubmit="return validateForm(this) && ValidateDropForm()">