• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to retrieve data from database when ever select in drop down list?

 
vijay Panner
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am developing one web based application using jsp. here I m using three drop down list , one is country , second is state and third one is Location.
when we select country in the country drop down list. then respective state data retrieve from database then will show in state drop down list.
and when we select state in the state drop down list then respective location data will retrieve from database and show in the location drop down list.
please help me, how to solve this problem?, which one i use in javascript,ajax?. please give me idea about it.
 
Komal Renu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vijay,

A better way to accomplish what you're trying to do is using Ajax. Its a very common scenario what you listed. You will get many tutorials online if you are new to ajax and dont know much about it.

Secondly, another way to do it is, on click of a value in the dropdown, you can use javascript to invoke an action that gets corresponding values for that selection from the DB.

Ofcourse, Ajax is a better way to do it.

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------
 
vijay Panner
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I have doubt in javascript, is it possible to make database connection in javascript?
 
Komal Renu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot make connections/access DB from Javascript.

Javascript is a scripting language used on the front end. so your JSP would have the dropdown, which whill have the OnClick event. OnClick you invoke a function in javascript that submits the form and your request to the action class.

So from Javascript you need to navigate to your action class and from there to the business manager which in turn communicates with the Data access layer. This is how the general flow is. Of course there might be some changes depending on the architecture of your application.

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------
 
vijay Panner
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestion
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic