1

I need to do some validate before form submit.

I can not modify the html code and existing js (the only way is to add new js file).

I tried this one:

$('form').submit(function() {
    alert("check");
    return false;
});

but it does not call.

I tried this one too:

$(document).on('submit', 'form', function(e) {
    alert("check");
    return false;
});

it calls correctly but only for alert().

How is it possible to set false for disable form submit when my checkFunction() returns false?

karl person
  • 263
  • 1
  • 9

2 Answers2

1

You can use jquery validation plugin for validation before form submit. It is better for that. You can refer below link:

https://jqueryvalidation.org/

Kartik Bhalala
  • 390
  • 1
  • 10
0

e.preventDefault should help you there, because it is preventing the default behavior of the submit.

$(document).on('submit', 'form', function(e) {
  e.preventDefault();
  alert("check");
  return false;
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Frederik
  • 66
  • 5