• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

selected index order - years

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
satya,
Perfect!!! Thanks again.
Mary
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic