I'm trying to stop the form submission, if an input text element is blank. The submit button is in an anchor page i.e out of my JSP where my JS function resides to stop the submission.
Submit button on anchor page:
<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 where the input text needs to be validated:
function validateBlankFieldsOnClickSearch(){
if (!document.getElementById("FromDate").value || !document.getElementById("ToDate").value) {
alert("Enter OrderDate range : Either FromDate or ToDate is blank!");
return false;
}
}
I'm getting the alert message on clicking the search button, but on clicking OK the search continues instead of stopping. I do not want to make any change to the anchor JSP's Submit button as it is being used by other JSPs as well.