Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Dynamic Combo Box in JSP using AJAX

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
Seriously? That's what you're going with? I prefer this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic