aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Dynamically populating drop down menu with database values 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 "Dynamically populating drop down menu with database values" Watch "Dynamically populating drop down menu with database values" New topic
Author

Dynamically populating drop down menu with database values

Suman Nandi
Greenhorn

Joined: Nov 19, 2009
Posts: 1
Hi,

I have a JSP page which calls a Servlet via AJAX (XMLHTTPRequest). The Servlet's task is to hit the database. Now I want the values coming from database to be displayed in JSP in a dropdown fashion. Please help.
yuvaraj KumarAmudhan
Ranch Hand

Joined: Aug 22, 2009
Posts: 110
in which manner you are receiving the data from the database?

in XML structure or something else?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Plenty of examples are available in Google...


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If you were using a modern JavaScript framework this would be even easier.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Moved to the HTML/JavaScript forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

David Newton wrote:If you were using a modern JavaScript framework this would be even easier.

Indeed, if the server-side resource were to just create the HTML fragment containing the options, the client-side code, using jQuery, would be as simple as:

Without jQuery, you'll need to do the Ajax "by hand" (not recommended) and use innerHTML to inject the options.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
actually you can not use innerHTML to add options since now all browser allow that to happen.

You would have to use

new Option("text", "value");

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

I guess jQuery handles the browser differences. Another reason to use jQuery rather than doing it "by hand".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamically populating drop down menu with database values