• 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

question about drop down menus and servlets...

 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys. I have a form with several drop down menus. The form is validated and if there's something wrong the user has to fill it out again. How do I keep what the user has selected in the drop down and the other options as well?
thanks
 
Author
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Originally posted by Andres Gonzalez:
Hey guys.

I have a form with several drop down menus. The form is validated and if there's something wrong the user has to fill it out again. How do I keep what the user has selected in the drop down and the other options as well?
thanks


dear
every drop down must be having a unique name i.e something like <select name="dropdown">. u can retrieve the value user has selected by using request.getParameter("dropdown"). & similarly for other drop downs...
hth
malhar
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try what Malhar has suggested Andres because that's how it's done. If you are still stuck then ask for code sample and I should be able to craft you an example. Things are a bit complex when you are populating the dropdown list from a database though...Good luck buddy!
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks guys... I think i got it my own way .
I have a bean, so I know what the user has selected. If there's an error in the form, I display all the values in the drop down menu, but the first option will be like this
<option checked><%=bean.getSelectetItem()%>
<option> another option </option>
.
.
or something like that, i don't have the code in this computer. So he/she can still choose a different option.
The disadvantage is that the option that the user has selected is shown twice. One at the very first option (what the use chose) and the same option where it originally was placed.
I was stuck with this problem for such a long time that didn't see any other solution.
Hope you guys understand what I explained above
.
thanks again
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
You could keep al the options of the dropdpwn in a ArrayList .
Your bean will give you the selectedItem.
For populating the dropdown you could have a for loop and inside the loop get the items from the list arrayList.getItem(index) .
You could have a check to see if the
arrayList.getItem(index).toString().equals(bean.getSelected())
to keep the option selected.
Thanks
Debanjana
 
reply
    Bookmark Topic Watch Topic
  • New Topic