1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to add a select dynamically and populate it with values from database

Discussion in 'JavaScript' started by sam_h, Oct 12, 2010.

  1. #1
    Hi people - it's been a while since I asked a question on here, but the time has come again!

    I would like to have a jsp page with a form consisting of several inputs and selects.

    When page loads for the first time, there is only one select (with values taken from database), but after clicking on link "add", the subsequent selects are added (using JavaScript and DOM).

    It seems to be pretty easy task, but I'm not sure how to populate the newly created select with data.

    Any help it greatly appreciated

    Sam
     
    sam_h, Oct 12, 2010 IP
  2. jocurileus

    jocurileus Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well, where do you get your data from when you add your new select?
    If it's the same as the old select you can stitch an id on the first form you create within your java page and then loop through it's elements and add them to the newly created select(this should be done when adding the newly element, and after checking it was rendered in DOM).
    That is the best I can do for the information you gave.
     
    jocurileus, Oct 15, 2010 IP
  3. max2010

    max2010 Greenhorn

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    you can do it easly with jquery, just google this: jquery dynamic select (as I did lol) you will find something useful (server side examples are in php anyway I'm sure you can easly convert into java jsp)
     
    max2010, Oct 15, 2010 IP