Search code examples
javascriptjqueryhtmlformssend

Put a jquery-function before form-send?


I have a form. I need to implement a jquery-file-upload before the form is beeing sent.

How can I capture if the send-button has been clicked, to display and preform a file-upload, and finaly send the form?


Solution

  • Use .submit()

    $( "#target" ).submit(function( event ) {
      alert( "Handler for .submit() called." );
      //event.preventDefault();
      return true;
    });
    

    submit() will trigger before html submit and will finish processing and then hand over to html submit if it returns true otherwise if returns false it stops the submit.