• Post Reply Bookmark Topic Watch Topic
  • New Topic

syntax and selected index and month

 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am rather new to java, tried to modify the below - had it working for years, but now am trying for months (selected index) and get the following error message.
line 9: Syntax: Misplaced construct(s)
this is on line 9:
String[] months = new String[];
11: Syntax: Expression expected after this token
this in on line 11:
cal.add(java.util.Calendar.MONTH,);
also, they need to be display like this, there is a alot of javascript and the servlet needs O1, not 1
OPTION>Month
<option value=01>January
<option value=02>February
..<option value=10>October
The help at this forum has been great. Thanks very much!!!

<html><head><title>Untitled</title></head>
<body>
<form name="Escc" method="POST" action=" ">
<%
String passedDobMn = (String) request.getParameter("dobMn");
if (passedDobMn==null) passedDobMn="";
String[] months = new String[];
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.add(java.util.Calendar.MONTH,);
for (int i=(months.length-1); i>=0; i--) {
months[i]= String.valueOf(cal.get(java.util.Calendar.MONTH));
cal.add(java.util.Calendar.MONTH,1);
}
%>
<select name="dobMn" >
<OPTION >month
<%
String sel = "";
for (int i=0;i<months.length;i++) {
if (months[i].equals(passedDobMn)) sel = "selected";
else sel = "";%>
<option value="<%= months[i] %>"
<%= sel %> >
<%= months[i] %>
</option>
<%}%>
</select>
</form>
</body>
</html>
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

String[] months = new String[];
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.add(java.util.Calendar.MONTH,);
for (int i=(months.length-1); i>=0; i--) {
months= String.valueOf(cal.get(java.util.Calendar.MONTH));
cal.add(java.util.Calendar.MONTH,1);

The foll. stmt is wrong.
[i]String[] months = new String[];

Assuming your application uses 12 months,
String[] months = new String[12];
regds.
- satya
 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
satya,
Thank You Again!
I ended up using the below, but what you just showed me is what I was looking for and would like to try out. You have been very helpful.
<%
String passedDobMn = (String) request.getParameter("dobMn");
if (passedDobMn==null) passedDobMn="0";
String months[] = {
"January" , "February" , "March" , "April", "May",
"June", "July", "August", "September", "October",
"November", "December"
};
int m = Integer.parseInt( passedDobMn )-1;
%>
Mary
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String months[] = {
"January" , "February" , "March" , "April", "May",
"June", "July", "August", "September", "October",
"November", "December"
};

This probably, is a better approach rather than your first one. Seems like you are trying to create an array of 12 Srtings, then getting instances of Calender, then valueOf(...). That is way too confusing than what you did above.
So, bottomline stick with what you got. Don't go for the new String[12].
My two cents......
- sayta
 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I appreciate your comment, will do that then, am then also going to go with the same idea for the days.
Mary
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!