• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieving contents from a select multiple=true input

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a form that has 2 select boxes where the multiple option is set to true. I am passing some values from the first box to the second box using javascript. This all works fine as the values transfer properly and everything.

Once I press submit I am going to an action where I try and collect the values from the second select box.

I have tried to retrieve them using:

request.getParameterValues("target")

but this always returned null.

Just to test I tried to return the values from the first box but this also returns null so I'm not sure what's going on. It collects the values from all other parameters on the form, just not for this one.

Anyone ever done this before? Know how to make it work?

Thanks
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post the relevant parts of your JSP?
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've done that and had it work, what you need to do is assign a String [] to your second select box (the one you're trying to get the data from) and replace the submit button with a standard html:button with an onclick event. The onclick event should iterate through the select box entries in javascript and set them all to selected then do your forms[0].submit.click();

Struts doesn't update the array used in your html ptions tags so if it was null before you'll still get null when trying to access the data afterwards. You might like to use an event handler to catch the enter key press and ignore it on that page too so the hidden submit button it only accessable by you through your javascript.

Hope this helps, let me know if you didn't understand any of it
 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would love to see how you did this, I'm working on something similiar but I was trying not use any javascript.

I have two multi-select boxes and I want to beable to remove value(s) from one and add it/them to the other (and vice versa). I have 3 submit buttons one add (takes value from right select box and places it in left select box) one remove (takes value from left select box and places it in right select box) and then save which saves changes the database accordingly. My actual actionform has 4 string[] types: member, notMember, selMember, notSelMember (member and not Member are the two multi select boxes).


inside the action class depending on the value of myAction, I add/subtract values in (notS)/(s)elmembers from the members/notmembers array.

I keep getting a "property members returns null" exception even though I'm setting the members property inside the action class.

I've even tried to store values for members/not members in the request b/c I think the above code might return null for the property members as its not part of the form.

 
reply
    Bookmark Topic Watch Topic
  • New Topic