This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding hidden values that is a list

 
steve kelly
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats the syntax for declaring a hidden field thats a list? And adding to it etc? I want to be able to store some rows when a user saves.

I currently have a screen with a spreadsheet where the user can collapse and expand rows via a plus/minus button. I want the screen to remember after the save which rows where collapsed or expanded and refresh accordingly.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64696
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All form elements with the same name will participate in the same request parameter of that name. The array of values can be retrieved from the request within the servlet via request.getParameterValues().
 
steve kelly
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do I implement it...like below?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64696
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
steve kelly wrote:how do I implement it...like below?


Does that seem like valid HTML to you? Remember, everything you do at the browser is just HTML. Any JSP-isms are just to iniitally generated the HTML page to send the browser.

As I said, all form elements with the same name become the array of values. So to create an array of "rowID" values:


 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As for the original question, if you want to have a dropdown list that's hidden, then in your drop down element use
if that's what you want. Otherwise if you want an array follow Bear's post
 
steve kelly
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I this is what I am doing...

I have this declaring my hidden field on jsp page


When user saves I have this code that iterates through the plus/minus rows and determines if they needed to ba added to a variable "rowID"



later when I want to access this variable the alert below is always undefined. I want to access whats been stored. How do I do this?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64696
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your row variable is declared deep within a function. It will only be available within that function. Declare it at a higher scope.

Though I'm still not exactly sure what you are trying to accomplish. What are you actually trying to collect?
 
steve kelly
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically the rows are collapsing plus/minus nested rows in a spreadsheet form. So I want the ability for user to click save and the screen to remember which lines they had previously expanded or collapsed after the save/submit.

Right now after saving I re-expand all lines and its very inconvient if you have lots of lines. Maybe I am just going about this totoally wrong?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64696
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And each row has a unique id, and you want to just send this list of ids to the server? (So that you can use the list to determine which rows are "open" next time the page is viewed?)
 
steve kelly
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:And each row has a unique id, and you want to just send this list of ids to the server? (So that you can use the list to determine which rows are "open" next time the page is viewed?)

what you said in the bold. yes
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64696
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you doing this at submit time? If so, how can it be determined if a row is opened or closed?

In any case, to send the info back to the server you can:
  • Create multiple hidden inputs as I detailed in a previous reply. If they all have the same name, the values can be retrieved as an array.
  • "Cheat" and create a single hidden input that contains the list as a comma-separated string that you can parse at the server.

  • The latter involves less logic on the page, and more on the server. The former, just the opposite.
     
    Consider Paul's rocket mass heater.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic