Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

get.paramater in form -selected index problem

 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have page one (x.jsp):
------------------------
<html>
<head>
<%@ page import="java.io.*, java.util.*, java.text.*" %>
<title>Untitled</title>
<% HashMap Info = new HashMap();
Info.put("dobYr","1950");
%>
</head>
<body>
<%= Info.get("dobYr") %>
<form name="passToEscc" method="POST" action="x-1.jsp">
<input type="hidden" name="dobYr" value="<%=Info.get("dobYr")%>">
<input type="submit" name="b1" value="Go"></form>
</body>
</html>
the dobYr value gets passed to page two:
(x-1.jsp)
---------------------------
<html><head><title>Untitled</title></head>
<body>
<form name="Escc" method="POST" action=" ">
<%
String passedDobYr = (String) request.getParameter("dobYr");
if (passedDobYr==null) passedDobYr="";
int start = 60; // when does the years start
int end = 19; // 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-60 to 2002-19
//needs to start with 1986
// next year it would be 2003-60 to 2003-19
// and end with 1986
%>
<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>
</form>
</body>
</html>
I get a selected index, but when view it on the screen of a browser, the years are double space, - that is there is a space between every year.
I can't seem to get rid of it.
any suggetsions
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"maryloo"
Your name doesn't follow the javaranch guidelines. Please take a moment and change your "Publicly Displayed Name" by editing your profile, to follow the guidelines available at http://www.javaranch.com/name.jsp
thanks for your cooperation.
- satya
 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry :roll:
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no sweat. That was fast, really.
Thanks.
- satya
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<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>

Your <option> tags don't seem to line up properly...
Shouldn't the "option" line in the for loop be something like:

Close the option tag properly.
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
Madhav,
Thank you that was it, I had to add the closing </option>
Thanks!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!