I want to prevent a form from being submitted once the submit button is clicked. It should capture all the data, but not send.
I’ve struggled with this a bit in an attempt to get it working, but to no avail. I’ve tried all the below methods, but nothing.
function saveDetails(form){
this.preventDefault();
}
function saveDetails(form){
$(form).preventDefault();
}
function saveDetails(form){
form.preventDefault();
}
I can capture the data easily by running $(form).serialize(); which works perfectly. But the above does not work for stopping the submit action. Any assistance?
you need to call it on
event.preventDefault().preventDefaultis the method of the DOM event-object. For example, you need to attach a handler to thesubmitevent, that handler must do all what you need but inside itt you have to call this method