In my form, the user has to enter 4 values to generate the multiplication table.
To validate the user's input I use jQuery. If the input is not valid (blank, non-integer number, etc) then the error message is displayed. The "Submit" button should only work when the input is valid.
I used this to prevent the form from submitting (source: Preventing a form from submitting in jQuery Validate plugin's submitHandler function):
$("#inputForm").submit(function(generateTable) {
generateTable.preventDefault();
}).validate({
//code
});
Here is the validate.js file:
function generateTable() {
//code
return false;
}
$(function() {
$("#inputForm").submit(function(e) {
e.preventDefault();
}).validate({
//rules
//messages
});
Here is HTML file:
<form id="inputForm" class = 'card p-3 bg-light' class="form-horizontal" onsubmit="return generateTable();">
The issue is that the form is getting submitted even if the input is not valid. How can I prevent the form from being submitted?