Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

selected index order - years  RSS feed

 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following which gives a acending order of the years 1920 -1986
How would I reverse this to decending; or 1986 - 1920
<form name="Escc" method="POST" action=" ">
<%
String passedDobYr = (String) request.getParameter("dobYr");
if (passedDobYr==null) passedDobYr="";
int start = 82; // when does the years start
int end = 16; // and when do they end
String[] years = new String[start-end+1];
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.add(java.util.Calendar.YEAR,-start);
for (int i=0;i<start-end+1;i++) {
years[i]= String.valueOf(cal.get(java.util.Calendar.YEAR));
cal.add(java.util.Calendar.YEAR,1);
}
// Here we have an array of years from 2002-16 to 2002-82
//needs to start with 1986
// next year it would be 2003-60 to 2003-16
// and end with 1920
%>
<select name="dobYr" >
<OPTION >Year
<%
String sel = "";
for (int i=0;i<years.length;i++) {
if (years[i].equals(passedDobYr)) sel = "selected";
else sel = "";%>
<option value="<%= years[i] %>"
<%= sel %> >
<%= years[i] %>
</option>
<%}%>
</select>
Thanks
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How would I reverse this to decending; or 1986 - 1920
for (int i=0;i<years.length;i++) {

How about........
for (int i=(years.length-1); i>=0; i--) {
regds.
- satya
[ March 16, 2002: Message edited by: Madhav Lakkapragada ]
 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
satya,
Perfect!!! Thanks again.
Mary
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!