wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Dynamic Combo Box in JSP using AJAX 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 "Dynamic Combo Box in JSP using AJAX" Watch "Dynamic Combo Box in JSP using AJAX" New topic
Author

Dynamic Combo Box in JSP using AJAX

Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Dear Ranchers,

I am doing a project, in which I want to populate the data in second combo box according the value selected in first combo box, reading from database.

My table structure is given below


The page contains 2 combo box, the first combo populates values from the table a1 when the page is loading. the second one has to populate using the corresponding value selected in combo1.

The values in the table are given below


Please help me with some sample codes,

Thank/Regards

Aravind Prasad
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
You can refer to this previous post regarding a similar issue
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Thankyou Mr.Anirvan,

As per your communication, I have checked in google.com and found one convincing sample code. I have done some changes to pick from my database table as well. But still there is no luck. I am getting an error message. Here with attaching the sample code



The database table design is given already in my previous post. There is a java script error I am getting.. Error is also given below



Please help me to resolve the error.

Thanks/Regards

Aravind Prasad
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
For starters, I have no clue where you got that code from, but I think what you should have tried more is to understand how AJAX works instead of resorting to a simple Ctrl+C & Ctrl+V
Anyways, some errors I can already point out are:
1) Are you even defining the method "getHttpObject()" anywhere?
2) xmlHttp.readyState=="complete" has no relevance. Infact it's not even correct. xmlHttp.readyState==4 (the first condition you use) is more like it.
3) You're not even checking whether the response status is correct (=200).

Before you start of implementing the cascaded dropdowns, it would hold you in good stead if you brushed up the fundamentals of AJAX.
For starters, here's how your showState() method should have looked like:


Thereof, I think a tutorial like this will help you complete the remaning part easily.
 
wood burning stoves
 
subject: Dynamic Combo Box in JSP using AJAX
 
Similar Threads
Three problems with mysql...
need help in JPA ANNOTATION regarding Inheritance.
Display full double values
Retreving PDF File from Database using Java
Dependent Combo Box