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 create select box

 
manas manas
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic