The way I've typically done what you're trying to do is with the following:
OK, so let's suppose I have three selects generated on page load, thus populated with data. Two of them are hidden by default. What happens if I don't click "Add" link and submit the form? I believe the hidden selects are submitted too. But at the servlet logic I need to distinguish them somehow. For example: Select 1 (visible) - attribute 1 - attribute 2 (selected by user) - attribute 3 Select 2 (hidden) - attribute 1 (selected by default) - attribute 2 - attribute 3 At the servlet code, how do I know that Select 1 was selected by user and Select 2 wasn't even visible, so it does not need processing?
Joined: May 11, 2008
I could create new option this way:
Document.forms['myform'].testselect.options = new Option('new text','new value');
But the point is that I need to get data from the database.
This is a classical Ajax example. Upon selection of the first dropdown, and Ajax request is performed to obtain the values with which to populate the second (and third, and so on). There are examples all over the net. Search for "cascading dropdowns" or "dependent dropdowns".
If you are using jQuery to do your Ajax for you (highly recommended), I have code examples that do this in the example code for my book on jQuery. You can download the code from the book's web page. The code for chapter 8 has the Ajax examples.