I´ve just started using Jquery, and are very impressed :)
Now I have this problem and I dont know the best solution for it, so I hope you could point me in the right direction.
On a page I am working on, I have this form where users can sign up. It is a signup form for family gymnastics. When the user (a parent) submits the form the data entered in the fields are stored in a database.
The problem is, that the user shall have the option to add 'x' number of children. So when the user clicks an "add child" button/link, jquery should shows a new table underneath with name, age birthdate fields for this child. The user can add as many children as he likes (there should probably be a limit). But when this form submits, should I then in some way iterate over all the added tables, and create a new child in the database for every new child table? And how do I iterate over a table collection in Jquery to get all fields? I cant generate unique ID´s for the fields... Or what kind of solution would fit this problem best?
I hope I have explained the problem well enough :)
In jQuery you can append some <input>'s to the form when a button is clicked and what I think you need to send this data is use the array notification in the name of the input field. This way you get an array of data at the back end (assuming you program in Rails or PHP). I could write a 1000 words and not get this clear so here's a link to a very informative post by Ben alman
Sorry, but I was to inaccurate. I am using asp.net C# for this project. And the page you linked to, doesent seem to fit my needs. Boiled down, my problem is: How do i create input fields dynamically based on the users needs, so when the user submits, I can collect all of the input field´s data, in a structured way. Not knowing how many input field there is, and not being able to refer to them with a unique id, like you normally would with a static form?
I already am creating a JSON object which I am sending to the server. But that really doesent have anything to do with my problem. The problem is still how I create, and later identify these dynamic input fields.
To create you can use the standard DOM insertion methods explained here To solve that specific problem (not knowing which names to "listen to") you could make a hidden input field and fill it with all the names of the inputs the back end should listen to.