Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

retrieve data to combo box

I manage to retrieve information from my table.

while (rs.next()) {
      out.println("Division");
}

But i have no idea how can i put it (Division) into my HTML code with <select></select> statement, how you will do that?

<select>
    <option value="DD">DD</option>
    <option value="CC">CC</option>    
    <option value="BB">BB</option>    
    <option value="AA">AA</option>
    <option value="FF">FF</option>
</select>

tried this already..not sure is it correct....,and doesnt look neat.

<select>
    <% while (rs.next()) { %>
     <option value="<%= rs.getString("Division") %>"> <%= rs.getString("Division") %> </option>
<% } %>
</select>

any other alternative?
0
kotakinabalu
Asked:
kotakinabalu
  • 5
  • 2
1 Solution
 
objectsCommented:
> and doesnt look neat.

jsp rarely does :)

what u have looks fine.
0
 
objectsCommented:
to make it neat you'd need to use a custom tag that knew how to generate your select from a result set.
0
 
objectsCommented:
the only change I'd make would be:

<select>
<%
while (rs.next())
{
   String div =   rs.getString("Division");
%>
     <option value="<%= div %>"> <%= div %> </option>
<% } %>
</select>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kotakinabaluAuthor Commented:
Yes, this code is working.
<select>
<%
while (rs.next())
{
  String div =   rs.getString("Division");
%>
    <option value="<%= div %>"> <%= div %> </option>
<% } %>
</select>

And i have change to taht as well. :-)

object, can share with me what i need to do if there is a duplicate data in my table and i don't want to retrieve them more than 1 time.

Division:
FF
AA
FF
CC
FF
BB
AA
FF
FF
DD
BB
DD
DD
DD

what will be my code can be?
0
 
objectsCommented:
You can achieve that by changing the sql query I think so it only returns unique entries. eg.

select distinct Division from mytable
0
 
kotakinabaluAuthor Commented:
TQ object...
0
 
objectsCommented:
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now