Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent page from reloading after form submit

Is there a way to detect and stop if page is reloading.

I have a page which is getting reloaded after successful submission of a form present in it. I want to have an event listener which sees if page is reloading and should stop it from being reloaded.

I cannot return false; for sucessful submit of registration form

like image 432
Green Wizard Avatar asked Nov 06 '25 00:11

Green Wizard


1 Answers

In your html:

<form onsubmit="myFunction()">
    Enter name: <input type="text">
    <input type="submit">
</form>

In your javascript:

myFunction = function(e) {
    // prevents default action to happen
    e.preventDefault();
    // do what ever you want to do here
    // i.e. perform a AJAX call
}
like image 68
Andre Avatar answered Nov 07 '25 16:11

Andre