DEV Community

loading...

jQuery Form multi submit preventDefault()

antelove19 profile image Falah Al Fitri Updated on ・1 min read

Happy Coding

https://stackoverflow.com/questions/11609295/jquery-submit-multiple-forms-in-a-page/59317426#59317426

/* get all form and loop */
$( "form" ).each( function () {

    /* addEventListener onsubmit each form */
    $( this ).bind( "submit", function (event) {

        /* return false */
        event.preventDefault();

        var form = event.target;

        /* display each props of forms */
        console.log( form ); // object formHTML
        console.log( "form id: " + form.id );
        console.log( "form action: " + form.action );
        console.log( "form method: " + form.method );

    } );

});

Demo repl.it

Discussion (0)

pic
Editor guide