LeanMoreTryMore
asked on
JSP - capture the value from the dropdown list
I got the JSP page which calls itself where the Search button is clicked.
I don't know how to capture the value from the drop down list and pass back the value to the page itself.
For example, if the user select 'Perth', from the downdown list, it then triggers off the search fuction (all work - ejb function) and return all records with the location, Perth.
But in the dropdown list, i dont know how to place the selected value.
Because whenever the page calls itself, it resets the dropdown list.
========================== ========== ========== ========== ========== ==
<td width="50" align="left" >
<select name="pickupLocation">
<% for (int j = 0;j < Constants.SR_STATUS.length ;j++) {
String value = Constants.SR_STATUS[j];
%>
<option value="<%=value%>"><%=valu e%></optio n>
<% } %>
</select>
</td>
========================== ========== ========== ========== ========== ==
I don't know how to capture the value from the drop down list and pass back the value to the page itself.
For example, if the user select 'Perth', from the downdown list, it then triggers off the search fuction (all work - ejb function) and return all records with the location, Perth.
But in the dropdown list, i dont know how to place the selected value.
Because whenever the page calls itself, it resets the dropdown list.
==========================
<td width="50" align="left" >
<select name="pickupLocation">
<% for (int j = 0;j < Constants.SR_STATUS.length
String value = Constants.SR_STATUS[j];
%>
<option value="<%=value%>"><%=valu
<% } %>
</select>
</td>
==========================
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ooops.. the else part needs to take the "selected" out of it
<% }else {%>
<option value="<%=value%>" ><%=value%></option>
<%}} %>
<% }else {%>
<option value="<%=value%>" ><%=value%></option>
<%}} %>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got compilation error
<option value="<%=value%>" <%= value.equals(request.getPa rameter("p ickupLocat ion") ? "selected=\"true\"" : "" %> ><%=value%></option>
<option value="<%=value%>" <%= value.equals(request.getPa
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Kuldeepchaturvedi: - works
but i really like to use mayankeagle's way.
also thanks for Jaax's suggest
you all have my points but why i got compilation error..what is the correct syntax using the following
<option value="<%=value%>" <%= value.equals(request.getPa rameter("p ickupLocat ion") ? "selected=\"true\"" : "" %> ><%=value%></option>
but i really like to use mayankeagle's way.
also thanks for Jaax's suggest
you all have my points but why i got compilation error..what is the correct syntax using the following
<option value="<%=value%>" <%= value.equals(request.getPa
>> value.equals(request.getPa rameter("p ickupLocat ion")
You're missing an ) there
value.equals ( request.getParameter ( "pickupLocation" ) )
You're missing an ) there
value.equals ( request.getParameter ( "pickupLocation" ) )
(so was I)
there is a missing parentheses in it...
Ooops..
Late again..:-)
Late again..:-)
No problem :)
ASKER
I did try Kuldeepchaturved's sample code. It works. many thanks for that.
Thankyou for you guys..
Thankyou for you guys..
<select name="pickupLocation">
<% for (int j = 0;j < Constants.SR_STATUS.length
String value = Constants.SR_STATUS[j];
if(value.equals(request.ge
%>
<option value="<%=value%>" selected="true"><%=value%>
<% }else {%>
<option value="<%=value%>" selected="true"><%=value%>
<%}} %>
</select>
</td>