Java Beginner
Java Beginner

Reputation: 1655

Generating Number using JSTL in JSP Page

I want to generate Age in Dropdown List in JSP page

<select name="cboAge" id="cboAge">
<%  
  for(int i=20;i<50;i++)
 { %>     
   <option value="<%= i%>"><%= i%></option>
 <% } %>  
</select>

Which Tag would be appropriate if I choose from jstl tag Library since the above method is highly discouraged one

Upvotes: 2

Views: 1297

Answers (2)

Meherzad
Meherzad

Reputation: 8553

Use jquery for this

</script><script type="text/javascript">
$(document).ready(function() {
    var selectAge = $("#selectAge"), i;
    for ( i = 20; i < 50; i++) {
        $(selectAge).append("<option value='" + options[i] + "'>" + i + "</option>");
    }
});

Hope this helps

Upvotes: -1

BalusC
BalusC

Reputation: 1109062

Use JSTL <c:forEach>.

<c:forEach begin="20" end="49" var="i">
    <option value="${i}">${i}</option>
</c:forEach>

Note that end is inclusive.

Upvotes: 7

Related Questions