Dibson
Dibson

Reputation: 3

How should I insert jQuery code before a submit action?

I want to manipulate form data with jQuery before I submit a form. The code looks like this:

$('form').submit(function(){
  event.preventDefault()
  console.log('Something');
  // What do I put here to make the form submit?
})

Upvotes: 0

Views: 36

Answers (1)

jackomelly
jackomelly

Reputation: 543

In the hypotesis you have a submit input in the form, you can try this:

$('form input[type=submit]').on('click', function(event){
  event.preventDefault()
  console.log('Something');
  // make the form submit
  $(this).parents('form').submit();
})

Upvotes: 1

Related Questions