Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

naming dynamic form elements

 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i have a jsp file in which the elements (eg. textfileds) are generated dynamically..wat is the best practice to name these elelemts..
is it a good practice append an int variable to the end of the textfilds name like txtfld1, txtfld2 ??
if i name all the textfields with the same name, is there any way to get the values of each of these textfields ??
thanks
raj.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can retrieve all the values if you name the fields the same by using request.getParameterValues() (rather than request.getParameter()). However, you will not be able to tell which value came from which field.
If that is an important distinction, then you will need to assign each field a unique name.
Which makes the most sense depends upon how your submission target needs to deal with the fields, which you did not discuss in your original question.
hth,
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic