I have an arraylist for Strings eqArray.
I need to show it in a drop-down list for which I'm using the following in my JSP:
<% 
    for(int count=0;count<eqArray.size();count++){ %>
            <option value="<%=eqArray.get(count)%>"><%=eqArray.get(count)%></option>  
     <%} 
%>
I have an eqName String which is part of eqArray and should be the selected value by default.
How do I go about it without having to check and set the first option as eqName always?
<% for(int count=0; count<eqArray.size(); count++){ %>
    <option value="<%= eqArray.get(count) %>" <%= (eqArray.get(count).equals("eqName"))?"selected":"" %> ><%= eqArray.get(count) %></option>  
<%} %>
                        Change the index of eqName element to 0 in the array, or use a conditional Statement.
<% 
for(int count=0; count < eqArray.size(); count++){ %>
        <%if(eqArray.equals("eqName"){ %>           
            <option  selected="selected" value="<%=eqArray.get(count)%>"><%=eqArray.get(count)%></option>  
        <%} %> 
        <option value="<%=eqArray.get(count)%>"><%=eqArray.get(count)%></option>  
 <%} %>
but use JSTL taglibs instead of using scriptlets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With