在JS中返回false,不停止JSP表单提交

return false in JS not stopping the JSP form submit

本文关键字:不停止 JSP 表单提交 false JS 返回      更新时间:2023-09-26

如果输入文本元素为空白,我试图停止表单提交。提交按钮位于锚页面中,即在我的JSP之外,我的JS函数驻留在那里以停止提交。

锚页上的提交按钮:

<a href="" onclick="document.body.style.cursor='wait';setMaxRecords();javascript:postFormFromSubmit(contextPath+'/console/'+entityType+'.list');return false;">
    <input class=button type=submit name="btnSearch" value='Search' alt="Click to begin Search" >
</a>
需要验证输入文本的

JSP:

function validateBlankFieldsOnClickSearch(){    
    if (!document.getElementById("FromDate").value || !document.getElementById("ToDate").value) {
        alert("Enter OrderDate range : Either FromDate or ToDate is blank!");
        return false;
    }       
}

我在点击搜索按钮时得到警告消息,但是在点击OK时,搜索继续而不是停止。我不想对锚JSP的Submit按钮做任何更改,因为其他JSP也在使用它。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<input id='fromDate'>
<input id='toDate'>

<button valiue="My Submit Button" onclick="if (
                        document.getElementById('fromDate').length==0 ||
                        document.getElementById('toDate').length==0
                    )
                    {
                        alert('Enter OrderDate range : Either FromDate or ToDate is blank!');
                    } else {
                        alert('my submit here');
                    }">
</button>
</body>
</html>