1

Hi and thanks for taking the time to asnwer my question.

I have the following problem. I have a form and a button which says "add new activities".

Whenever the button is clicked I add a new set of elements, namely 2 drop down menus + text area. How can I get the values of these newly created elements in code behind since I cannot know their ids up front?

If there is something unclear about my question, please let me know.

Thanks again!

6
  • 1
    Can you show your code and explain it better ? Commented Dec 7, 2012 at 18:06
  • I have not code.. I was thinking about how to go about it and ran into this problem.. I wrote what is happening on the form. A user clicks a button and a new <li> element is added to the form containing 2 ddls and a text area. there may be 100 such li elements depending on how many times a user clicks on the button. At the bottom there is a save button. When the save button is clicked i want to retrieve the values of the dynamically created ddls and textareas Commented Dec 7, 2012 at 18:09
  • @Dragan: How you adding elements?? Can you add a css-class at the same time when you adding elements?? Commented Dec 7, 2012 at 18:10
  • I haven't written that script yet.. However I have done the exact same thing in Spring using jquery and it is pretty easy. TO answer your question @huMpty duMpty, YES, i can add css class to the newly created elements. Not only that I can but I must in order for all of them to look like the design Commented Dec 7, 2012 at 18:12
  • So, the first thing you have to do before ask for help is TRY. Commented Dec 7, 2012 at 18:13

2 Answers 2

1

But you must be setting id's (more importantly - name attributes) of new elements using certain pattern. Use the same pattern in a loop in server-side code to get values from Request.Form. Provide a hidden input where you put the total count of items added for the server-side to know the upper bound of loop counter.

Sign up to request clarification or add additional context in comments.

2 Comments

wow this is exactly what I was looking for.. In Spring I did it the same way.. all new elements had to have the same name attribute and I could get an array of the values of all elements with that name.
Exactly what I needed. Thanks so much. Accepted your answer
0

You should set the ids when you create the elements if you plan to access them again So if you this is your text area:

var textarea = document.createElement('textarea');

You can set the id to like this:

textarea.id = "taId";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.