Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Combobox Problem

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have looked through some examples of trying to populate one combobox depending on another but im still not sure. Im using struts,jsp,java for my project. I have the first combobox populated but now i have to populate the second combobox depending on what i have selected in the first one. I am taking the fields from a database. The following is the jsp code i have, Can someone please help me?

<TD>Origin: <html:select property="origin">
<% ArrayList list = new ArrayList();
DatabaseOperations databaseOperations = new DatabaseOperations();
list = databaseOperations.getOrigins(); %>
for(int i=0; i < list.size(); i++)
<html ption value='<%=list.get(i).toString()%>'>
</html ption>
<% } %>
<TD>Destination: <html:select property="destination">

Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three ways that I know of to handle the problem of the contents of combo box B being dependent on what the user selects in combo box A:

1- If there are only a few different sets of possible options for combo box B, store each set of options as a javaScript array. Then, when the user makes a selection on combo box A, use the onChange method to call a javaScript function to swap out the options.

2- If there are a lot of different sets of possible options, or if the lists are long, Use a server-side approach: Use the onChange event from combo box A to submit the form. The Action class then reads the value from Combo box a and prepares the list of options for combo box B. It then redisplays the page with the focus on combo box B.

3- Use AJAX to make a server-side call to get the options and refresh them without refreshing the entire page. You'll have to download one of the AJAX open source projects (Such as DWR) and study up on AJAX in order to use this option.
[ February 02, 2006: Message edited by: Merrill Higginson ]
Everybody's invited. Except this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic