This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

How to populate select box based on value from another select

 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two select box on a web page.On selecting value from first select box i have to populate 2nd select.The values for 2nd select box comes from database.I am not able to understand how i will do it using struts1.if anyone has any link please post here.

Thanks
 
Author
Posts: 3443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean value for the first select box comes from the database. To populate your second select box from the first, you may have to use java script or some rich component like richfaces.
[ August 15, 2008: Message edited by: arulk pillai ]
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a hardcoded values in first select box.The user will choose some value from first select box and based on values from first select box i have to populate the 2nd selectbox for user.The values for 2nd selectbox comes from database.Both selectbox's are on same web page.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to do this with Ajax and a little Javascript. You can create/delete select box elements on-the-fly...the Ajax will help you query the database without a reload.

This assumes you are not trying to populate the select box with 100's of options.
 
Marshal
Posts: 67336
171
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by arulk pillai:
or some rich component like richfaces.


Talk about using atomic bombs to crack walnuts!

This is one of the most common Ajax examples you could think of. It has been discussed many times in the HTML forum and there are examples all over the web. Search for "dependent" or "cascading" dropdowns.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we solve above problem without using AJAX?
 
author & internet detective
Posts: 39760
797
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Gowher Naik:
Can we solve above problem without using AJAX?


If there are a small number of values in the second box, you could store them all on the page using a JavaScript map and loop through the map to populate the list when each element is selected. This only works for a relatively small number of combinations since you don't want to make the page download huge.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

If you dont want to use ajax then second selct box can be filled by reloading your jsp page again with new values.
i.e
Initially 1 select box with values and 2nd empty
on select of option in 1st select box submit your jsp page and reload same page with values in 2nd select box.

But why you dont want to use AJAX any specific reasons.
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!