File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to retrieve data from database when ever select in drop down list? 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 "How to retrieve data from database when ever select in drop down list?" Watch "How to retrieve data from database when ever select in drop down list?" New topic
Author

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

vijay Panner
Ranch Hand

Joined: Sep 29, 2010
Posts: 30
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

Joined: Jul 21, 2011
Posts: 51
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

Joined: Sep 29, 2010
Posts: 30
Thanks, I have doubt in javascript, is it possible to make database connection in javascript?
Komal Renu
Ranch Hand

Joined: Jul 21, 2011
Posts: 51
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

Joined: Sep 29, 2010
Posts: 30
Thanks for your suggestion
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

See this recent topic which discusses the same issue.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retrieve data from database when ever select in drop down list?