Harshit Agarwal
Harshit Agarwal

Reputation: 1345

serializing a jquery template form into json using jquery

I have a form for which I use JQUERY templates, as there can be multiple fields for an attribute. For eg. a user can have multiple phone numbers. So, he can add fields dynamically by pressing the option "add one more number". In this way multiple fields are added but all have the same name.
How should I serialize this kind of form data into a JSON object?
--Thanks in advance

Upvotes: 0

Views: 545

Answers (2)

Yogesh
Yogesh

Reputation: 924

  • You can set name attribute for multiple fields to consider it as array. Example is below <input type="text" name="phone[]"> <input type="text" name="phone[]"> <input type="text" name="phone[]">

  • Now for submitting you can use serializeArray() function to post the data to serverside script

I hope this will work for you

Upvotes: 0

Jason
Jason

Reputation: 15931

You can serialize a form with $(form).serialize ()

I'm not sure what the element id has to do with anything, but they should be unique on a page.

Upvotes: 1

Related Questions