This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic addition of items to combo inJSP

 
Shunmu U
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am searching for a procedure to add the elements fetch from a database to a combo box in JSP.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most important thing you have to understand with JSP is that JSP is just a way of describing a program to write HTML pages. So if you want to produce a selection list (although, remember that the HTML "select" tag is not quite the same as a Windows "combo box"), the steps are as follows:
  • practice on a regular HTML file until you are happy with the syntax of the HTML "select" tag.
  • copy the "select" code you have tested into your JSP
  • replace the hard-coded "<option>" tags with a loop reading the values from your database results and writing out similar tags to the output stream


  • Does that help?
     
    Shunmu U
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Wonderful ... It worked well ... Thanks a lot for ur help ..
     
    steve souza
    Ranch Hand
    Posts: 862
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    For an easier way to generate HTML elements such as tables, listboxes, drop down listboxes, multi select listboxes and more check out the FormattedDataSet (http://www.fdsapi.com).
    It is as easy as the following coe. Note that the drop down list box code highlights the selected value too.

    The site has a live demo that allows you to type in queries and another that creates standard html elements such as list boxes off of 2 dimensional arrays (another supported datatype, but it would work the same for ResultSets or queries too).
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!