Dirty Bird Design
Dirty Bird Design

Reputation: 5553

Easiest way to alert a form's data

Simple question I can't seem to get right. I have a form #formOne, I need to alert it's data. Something isn't working,

$("#formOne").submit(function(){
  alert("you are submitting" + data);
)};

If not data what do you use after +?

Thanks!

Upvotes: 2

Views: 12668

Answers (1)

Nick Craver
Nick Craver

Reputation: 630549

You can use .serialize() to see what the POST string looks like:

$("#formOne").submit(function(){
  alert("you are submitting" + $(this).serialize());
});

Make sure that #formOne is the form itself, so that this refers to the <form> element when serializing. For debugging you may always want to try this instead (using Firebug or Chrome):

$("#formOne").submit(function(){
  console.log($(this).serializeArray());
});

This will print out as an array of objects with a name and a value property, a bit easier to read, at least to me.

Upvotes: 5

Related Questions