• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamic Combo Box in JSP using AJAX

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can refer to this previous post regarding a similar issue
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic