File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes populate select box dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "populate select box dynamically" Watch "populate select box dynamically" New topic

populate select box dynamically

drick brates

Joined: Jul 01, 2006
Posts: 1
like country and states having two select boxes
if i select country from first select box it will populate second select box from database using mysql;(jsp,javascript)
plz give me the fair code

waiting for the code...............

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865


There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

JavaRanch Sheriff

[Asking smart questions] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Originally posted by santhoshreq:

waiting for the code

You will likely wait a long time. JavaRanch is not a code mill, it is a learning site. You are expected to do your own work and come here for help with it.

The specific question you asked is a very common one that you are likely to find many examples of with a little search effort on your part.
Kiran Joshi
Ranch Hand

Joined: Sep 04, 2005
Posts: 54
Few things that I can tell you in this.

I assume you have two combo boxes first is State (province) & second is city. You want to show the cities in the selected state.

1) Get the initial values for the state,that you can get using some servlet.
2) Write one javascript function that will create HttpRequest using XMLHttpRequest() activex object , & pass your selected state as a request parameter to the the servlet.
3) This servlet should be able to fetch the cities using the request parameter,should prepare a recordset in the form of a XML file & send it to the client.
4) Your client should interpret this xml using DOM & create the cities on the fly.

how to do this every thing,this information is scattered in this group only.

hope ,this helps.
[ July 04, 2006: Message edited by: Kiran Joshi ]
I agree. Here's the link:
subject: populate select box dynamically
It's not a secret anymore!