Cannot add or change onSubmit () attribute using jQuery

I have a form and two buttons. I want to change onsubmit attributeforms using these buttons using jQuery.

I tried

$("#form").attr("onsubmit","newValue")

but this does not change the onsubmit attribute and does not add the attribute to the form.

Please, help.

+3
source share
1 answer

Just use $ ("# form"). submit ();

Like this:

$("#form").submit(function(e){
//Prevent form submit: e.preventDefault()
//Do whatever
});
+7
source

All Articles