1

I have a problem that is common, but I am not quite sure exactly how do go about solving it.

My situation is I have a form that will have a drop down of States. I also have a drop down that should have military installations(bases), but the bases that are populated are dependent on the value of the state dropdown.

In my database I will have a table BASES such as the following most likely.

BASES Table
            int base_id
            varchar state
            varchar base_name
            varcar  city

When a customer selects a state, I need to query all the bases in that state. and return them and populate the bases drop down. I am well aware that I can do this easily by just posting the data to the server as form data, but I would rather find a simpler solution and I know ajax is used to solve problems like this one.

I am entry level, and ajax is a new topic for me so any help I can get would be appreciated.

I am using Java/JSP/Servlets and am using MySQL.

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
TheJediCowboy
  • 8,924
  • 28
  • 136
  • 208
  • You could simplify this by listing all the bases against the state of Maine, because I've often seen on the internet ... All your bases are belong to ME ;) – crowne Jul 26 '10 at 22:31
  • I've answered this kind of question before [Populating child dropdowns in JSP/Servlet](http://stackoverflow.com/questions/2263996/populating-child-dropdownlists-in-jsp-servlet). – BalusC Jul 26 '10 at 23:35

2 Answers2

2

If you think that AJAX is the solution, and you're using Java, then check out DWR. It allows you to trivially expose Java objects in Javascript. You can create a server-side object to derive your list of data for pull-down menus and easily expose this in Javascript.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
1

This can all be solved with javascript alone if you hardcoded the state/base relationship into an array(s) in the javascript file.

Here is an example I found on the internet.

http://www.javascriptkit.com/javatutors/selectcontent2.shtml

buckbova
  • 1,213
  • 6
  • 11