tags:

views:

30

answers:

1

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!

+1  A: 

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.

Nick Craver
@Nick - as usual thanks! It was a curiosity, as im sure ill have to show it at some point. thx man!
Dirty Bird Design
and if it's not? say the submit function is bound to a button, maybe #sbtBtn? :) I tried plugging in $("#formOne") in place of $(this) - no joy
Dirty Bird Design
That's nice. +1
Braveyard
@Dirty - The `submit` event is on the `<form>`, no matter where you're firing it from, you should use that as your attachment point, even if something else *triggers* it, your submit handler should be on the `<form>` itself.
Nick Craver
@Nick - awesome. firebug, much better. Thanks man. thats slick.
Dirty Bird Design
@Dirty - welcome!
Nick Craver