tags:

views:

36

answers:

2

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.

+1  A: 

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
Is This efficient if there is up to 250 bases?
CitadelCSAlum
what would it look like hardcoding the state/base relationship, I wasn't aware you could do this.
CitadelCSAlum
+2  A: 

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