我試圖停止表單提交,如果輸入文本元素爲空。提交按鈕位於錨定頁面,即離開我的JS函數駐留的位置以停止提交。在JS中不返回false不停止JSP表單提交
提交錨頁面上的按鈕:
<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;
}
}
我得到的點擊搜索按鈕警報消息,但點擊確定搜索繼續而不是停止。我不想對主JSP的Submit按鈕做任何更改,因爲它也被其他JSP使用。
的[JavaScript不能阻止提交JSP頁面上,爲什麼?]可能的複製(http://stackoverflow.com/questions/22764299/javascript-can-not-prevent-submit-on-jsp-page - 爲什麼) –
更好的重複:http://stackoverflow.com/questions/8664486/javascript-to-stop-form-submission –
無關,但這是一些相當艱難的HTML推理。將點擊處理程序附加到其他位置可能會更好,並將所有功能包含在單個處理程序中。 –