SNAG
SNAG

Reputation: 2113

Jquery - Form data in submit function

I have a form with a large number of dynamically generated elements. in the submit handler I would like to get all the data at once rather than going by each id. Is there anyway to do it?

Upvotes: 1

Views: 1145

Answers (3)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

You could use:

var yourFormData = $('#yourFormId').serialize()

Upvotes: 3

silly
silly

Reputation: 7887

jQuery('your-form-selector').submit(function() {
    var yourKeyMap = jQuery(this).serializeArray();
});

Upvotes: 3

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123377

your question is not very clear but maybe you're looking for serialize() or serializeArray() jQuery methods

http://api.jquery.com/serialize/
http://api.jquery.com/serializeArray/

e.g

The .serializeArray() method creates a JavaScript array of objects, ready to be encoded as a JSON string. It operates on a jQuery object representing a set of form elements. The form elements can be of several types:

Upvotes: 3

Related Questions