Edward Beringuela Edward Beringuela - 1 year ago 101
Java Question

Reverse JSTL for each loop for year (using dropdown)

I want to create a dropdown menu that starts with the current year, or at least starts with 2016 and ends with 1900

I only have this code right mow but is not working properly.

<select id="year" name="year">
<c:forEach begin="1900" end="2016" var="val">
<c:set var="decr" value="${2016-val}"/>
<option value="${decr}" ${birthYear == decr ? 'selected' : ''}>${decr}</option>

Answer Source

Try this.

<select id="year" name="year">
            <c:forEach begin="0" end="116" var="val">
                <c:set var="decr" value="${2016 - val}"/>
                <option value="${decr}" ${birthYear == decr ? "selected='selected'": ''}>${decr}</option>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download