aspose file tools*
The moose likes Servlets and the fly likes dynamically create select box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "dynamically create select box" Watch "dynamically create select box" New topic
Author

dynamically create select box

manas manas
Greenhorn

Joined: Nov 18, 2004
Posts: 1
dear friends
recently i was developing one application in which i was required to dynamically create a given number of select box depending on number selected by the user from another select box in runtime and the option of the former select box(ie select box's created dynamically ) have to be be retrive from the database which is sql.
can anybody help me solving this problem?

manash
Abhimanyu Kumar
Greenhorn

Joined: Nov 05, 2004
Posts: 12
Originally posted by manas manas:
dear friends
recently i was developing one application in which i was required to dynamically create a given number of select box depending on number selected by the user from another select box in runtime and the option of the former select box(ie select box's created dynamically ) have to be be retrive from the database which is sql.
can anybody help me solving this problem?

manash


hmm..i'll give it a try.. (i'm assuming that you are writing a jsp )
submit the form on the onchange event of the first select box (containing number of select boxes to be displayed)
get the selected value of first select box by request.getParameter()
use a while loop with this value and generate the html code to create the select boxes

something like this...

(pls take care of runtime exceptions , like NPE)
<% int noOfSelBoxes = new Integer(request.getParameter("selectBox1")).intValue();
%>
// your other html code

<% while(noOfSelBoxes >0) { %>
<tr>
// here goes your select box code
</tr>
<% noOfSelBoxes--;
} %>

Hope this helps.

Regards,
Abhimanyu
[ November 18, 2004: Message edited by: Abhimanyu Kumar ]

"Where there's a will, I want to be in it."
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
If you were to take care to write it out in proper English maybe you would understand the problem better.
It would certainly lead to people here understanding it better and maybe even spend some time to help you rather than think what a lazy careless person it is who doesn't even make the effort to word his questions in proper English.

What you want is actually quite easy and has been done many times before. I'm sure you can figure out how to do it if you just think about it a bit, which you could do while waiting for someone to write your code for you which is unlikely to happen...


42
 
wood burning stoves
 
subject: dynamically create select box