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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any experts out there!!? HELP!

Status
Not open for further replies.

LucyL

Technical User
Feb 20, 2002
113
US
Hi,
I have a drop down menu which is populated from the database. What I want to do now is take whatever value the user selects from the drop down, assign it to a variable and use this to retrieve values from the database. I'm new to java and am unsure of the syntax.
Great if anyone can help! :)
The code so far is as follows for the drop down:

<% Vector v = (Vector)session.getAttribute(&quot;stocks&quot;);
Stock s; %>

<table border = 1 bordercolor = &quot;green&quot; width = &quot;100%&quot; align = &quot;center&quot;>
<tr>
<td><b>Symbol</b></td>
</tr>

<tr>
<%
for(int i =0; i< v.size(); i++)
{
s =(Stock)v.elementAt(i);
String symbol = s.getStockSymbol();
%>
<td>
<select><option><%=symbol%></option></select>
</td>
</tr>
<%
}//end for loop
%>
</table>
 
You must give your <select> a name attribute, i.e. have something like <SELECT NAME=&quot;STOCK_OPTION&quot;>.
Also, start and end the <select> OUTSIDE the for loop, so have
<select NAME=&quot;STOCK_OPTION&quot;>
<%
for(...)
{
%>
<option....>
<%
}
%>
</SELECT>
Also each option must be given a value. your <%=symbol%> only displays text, it doesn't store anything in the <SELECT>.
So for each opton, have <option VALUE=&quot;<%=symbol%>&quot;><%=symbol%></option>

In your Servlet once the request is sumbitted you can access the value selected by using
String xx = request.getParameter(&quot;STOCK_OPTION&quot;);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top