setting listener to form submit

59 Views Asked by At

I want to set listener to submission of any form within a div using on function. I want even the dynamically added forms to have the listener. It should work whether the form is submitted using an input type of submit or by a button. I tried it as below:

     $(document).ready(function(){
      $("#mainContent").on('submit', 'form', function(e){
        e.preventDefault();
        var formId = $(this).attr(id');
        //submitForm(form, '#mainContent');
        alert("Form is going to be submitted. Form Id: "+formId);

      });
    }

It is not working. Where am I going wrong?

0

There are 0 best solutions below