Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box using JSP

Status
Not open for further replies.

chmanio

Programmer
Dec 16, 2002
20
0
0
PH
im querying a database and i want to store the results in a combo box. im using the following code :

<select>
<option><%
while (rs1.next()) {
out.println(rs1.getString(1));
}
%>
</option>
</select>

my problem is the data stored in the combo box are concatenated in a single row.

example : value1 value2 value3 value4 value5

i want the result to be:

value1
value2
value3
value4
value5

pls help!

thanks!
 
Code:
<%! String myChoice[] = {"zero","one","two","three"};
%>
<html>
<head>
</head>
<body>
<form name="f1">
<select name="s1">
<% for(int i=0; i<myChoice.length; i++) {%>
<option value="<%=i%>"><%=myChoice[i]%></option>
<% }%>
</select>
</form>
</body>
</html>
 
Code:
<%!
    // get all string before output html
    // this is not complete code
    int MAXREC = 20;
    int count=-1;
    String myChoiceB[] = new String[MAXREC];
%>
<%
  while (rs1.next()) {    
    count++;
    if (count>MAXREC-1)
       break;
    myChoiceB[count]=rs1.getString(1);
  } 
%>
<html>
<head>
</head>
<body>
<form name="f1">
<select name="s1">
<% for(int i=0; i<=count; i++) {%>
<option value="<%=i%>"><%=myChoiceB[i]%></option>
<% }%>
</select>
</form>
<%=count%>
</body>
</html>
</form>
</body>
</html>
 
Code:
// fix logical bug
<%
  while (rs1.next()) {    
    count++;
    if (count>MAXREC-1)
       {
        count = MAXREC-1;
        break;
       }
    myChoiceB[count]=rs1.getString(1);
  } 
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top