I solved it this way, due my code is a little bit different this may be helpful for other people. My initial code looked like this.
<form id="enrollstudentform" onsubmit="return enrollStudents()">
...
</form>
My js function looked like
function enrollStudents() {
// Stop Form.
event.preventDefault();
// Other code
}
I had to pass the parameter event in the function call and receive it in the function.
<form id="enrollstudentform" onsubmit="return enrollStudents(event)">
...
</form>
js code:
function enrollStudents(event) {
// Stop Form.
event.preventDefault();
// Other code
}
I hope it helps.