How to gather values of multiple JS-generated input fields?
I have a form 开发者_JAVA百科in which I have an add button. When the add button is clicked a new text box appears where user can enter some data. The user can click add button any number of times. I am using javascript to dynamically generate textboxes. I can maintain a count of the number of textboxes generated. All the values entered in these text boxes have to be stored in database using JSP. How can I store those values in the database as I do not know how many textboxes were created?
You could assign the text box count (increment an integer every time they click the Add button) to a hidden input field in the form, then retrieve the value of that field in the JSP when the form is posted.
If you give each new text box a new name, e.g. text{count}, then in your JSP just get the parameters from text0 to text{maxCount}, where maxCount is the count from the hidden field.
精彩评论