表单仍然提交甚至js验证返回false

时间:2015-09-29 18:03:02

标签: javascript

在表单提交时,将调用validateForm()。 它返回false,但仍然被提交。我用它作为弹簧形式。

function validateForm() {
    var error = "";
    var caTicketNoID = document.forms["caTicketForm"]["caTicketNoID"].value;
    if (caTicketNoID == null || caTicketNoID == "") {
        error += "Ticket Id must be filled out\n";
    }
    var description = document.forms["caTicketForm"]["description"].value;
    if (description == null || description == "") {
        error += "Description must be filled out\n";
    }
    var priority = document.forms["caTicketForm"]["priority"].value;
    if (priority == null || priority == "") {
        error += "Priority must be filled out\n";
    }
    var moduleId = document.forms["caTicketForm"]["moduleId.id"].value;
    if (moduleId == null || moduleId == "") {
        error += "ModuleId must be filled out\n";
    }
    var landscape = document.forms["caTicketForm"]["landscape"].value;
    if (landscape == null || landscape == "") {
        error += "Landscape must be filled out\n";
    }
    var unit = document.forms["caTicketForm"]["unit"].value;
    if (unit == null || unit == "") {
        error += "Unit must be filled out\n";
    }
    var assigneeNameId = document.forms["caTicketForm"]["assigneeNameId"].value;
    if (assigneeNameId == null || assigneeNameId == "") {
        error += "AssigneeName must be filled out\n";
    }
    var reviewer = document.forms["caTicketForm"]["reviewer"].value;
    if (reviewer == null || reviewer == "") {
        error += "Reviewer must be filled out\n";
    }
    var region = document.forms["caTicketForm"]["region"].value;
    if (region == null || region == "") {
        error += "Region must be filled out\n";
    }
    var solutionReadyForReviewId = document.forms["caTicketForm"]["solutionReadyForReviewId"].value;
    if (solutionReadyForReviewId == null || solutionReadyForReviewId == "") {
        error += "Solution Ready For Review must be filled out\n";
    }
    var groupId = document.forms["caTicketForm"]["groupId"].value;
    if (groupId == null || groupId == "") {
        error += "Group must be filled out\n";
    }
    if (error == "") {
        return true;
    } else {
        ShowError(error);
        return false;
    }
}

Html代码

  <form:form method="post" id="caTicketForm" name="caTicketForm" modelAttribute=""
    action="${pageContext.request.contextPath}/caticket/createTicket" onsubmit="return validateForm()">

0 个答案:

没有答案