I have a form with many input fields.
When I catch the submit form event with jQuery, is it possible to get all the input fields of that form in an associative array?
I have a form with many input fields.
When I catch the submit form event with jQuery, is it possible to get all the input fields of that form in an associative array?
All answers are good, but if there's a field that you like to ignore in that function? Easy, give the field a property, for example ignore_this:
And in your Serialize Function:
That's the way you ignore some fields.
http://api.jquery.com/serializearray/
This can also be done without jQuery using the XMLHttpRequest Level 2 FormData object
http://www.w3.org/TR/2010/WD-XMLHttpRequest2-20100907/#the-formdata-interface
Late to the party on this question, but this is even easier:
jQuery's
serializeArray
does not include disabled fields, so if you need those too, try:Here is another solution, this way you can fetch all data about the form and use it in a serverside call or something.
You can then use this with ajax calls:
Hope this is of any use for any of you :)
Sometimes I find getting one at a time is more useful. For that, there's this: