• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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: 3445
  • 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.
 
Sheriff
Posts: 67399
173
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: 39996
807
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.
 
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic