function editvalidation() {
var isDataValid = true;
var currentCourseO = document.getElementById("currentCourseNo");
var newCourseNoO = document.getElementById("newCourseNo");
var currentCourseMsgO = document.getElementById("currentAlert");
var newCourseMsgO = document.getElementById("newAlert");
if (currentCourseO.value == "") {
currentCourseMsgO.innerHTML = "Please Select a Course to edit from the Course Drop Down Menu";
newCourseMsgO.innerHTML = "";
isDataValid = false;
} else {
currentCourseMsgO.innerHTML = "";
}
if (newCourseNoO.value == "") {
newCourseMsgO.innerHTML = "Please fill in the Course ID in your Edit";
isDataValid = false;
} else {
newCourseMsgO.innerHTML = "";
}
return isDataValid;
}
嗨,在上面的代码中我要做的是,如果满足currentCourseO.value == ""
,则显示其字符串消息,但不显示newCourseMsgO
的字符串消息。
如果未满足currentCourseO.value == ""
,则显示newCourseMsgO
的字符串,如果符合此验证,则显示newCourseMsgO.innerHTML = "Please fill in the Course ID in your Edit";
。
目前,当newCourseMsgO
遇到currentCourseO.value == ""
时,它不会隐藏{{1}}的字符串。我可以请用javascript回答。
答案 0 :(得分:1)
听起来你应该连接两个if-else语句,现在它们并不依赖于彼此。试试这个:
if (currentCourseO.value == "") {
currentCourseMsgO.innerHTML = "Please Select a Course to edit from the Course Drop Down Menu";
newCourseMsgO.innerHTML = "";
isDataValid = false;
} else {
if (newCourseNoO.value == "") {
newCourseMsgO.innerHTML = "Please fill in the Course ID in your Edit";
isDataValid = false;
} else{
newCourseMsgO.innerHTML = "";
}
}