Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically populating drop down menu with database values

 
Suman Nandi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in which manner you are receiving the data from the database?

in XML structure or something else?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plenty of examples are available in Google...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were using a modern JavaScript framework this would be even easier.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the HTML/JavaScript forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess jQuery handles the browser differences. Another reason to use jQuery rather than doing it "by hand".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic