• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

storing values chosen from dropdown

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a dropdown box and the user can select as many as he wants. I have another dropdown that stores the user selections. I want to display the user selections in the confirmation page.

form-property name="chosenstates" type="java.lang.String[]"

Action class
String [] states= (String [])stateForm.get("chosenstates");
myStateFormbean.setStates(states);

JSP
myForm.getStates()(loop thru array is not working)

The above code is not working..How do I do this?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid you haven't given us enough information to help solve the problem. Please show us the code that's not working and the error messages you're getting.
 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
user can choose upto a max of 3 states. The states chosen are placed in chosenstates dropdown using javascript addOptions.

My chosenstates dropdown gets successfully populated based on the user's selections in states box. This works perfectly. When I submit the home.jsp page I try to display the chosen states in confirm.jsp. None of the states show up. I see the array length as 0.

Is this a right way to store values chosen by user? or is there a more good aproach?

home.jsp





Struts-config



Action class


confirm.jsp //returns nothing.


[ March 17, 2007: Message edited by: shah rah ]
[ March 17, 2007: Message edited by: shah rah ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep in mind that the only id values that will get submitted are the ones that are actually selected. You have added the items to you second list but nothing will be submitted unless the items are selected. What I have done for this type of page is to add some java script to select all the items in the list of chosen items when the user clicks the submit button.

- Brent
 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to select all the items in second list using javascript?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just loop through the options, setting the selected property of each one to true. Example:
 
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic