Question

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

Was it helpful?

Solution

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.

OTHER TIPS

  • 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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top