简体   繁体   中英

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

Use JSTL <c:forEach> .

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

Note that end is inclusive.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM