Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

get.parameter and text box  RSS feed

 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting two errors when trying to pass a value to a text box. I need to check if it is selcted or will remain empty (have alot of Javascript).
the code:
<%
String passedBirthDateMonth = (String) request.getParameter("birthDateMonth");
if (passedBirthDateMonth==null) passedBirthDateMonth=" ";
int cMonth=Integer.parseIntpassedBirthDateMonth );
%>

<%
String cMonth = ""; {
if cMonth = "selected";
else cMonth = "";%>
<input type="text" name="calculatedElecSerYear" value"<%= cMonth %>"><%
}%>
and the errors:
Syntax: Invalid Type
Syntax: Unexpected symbol ignored
or maybe that is all more then I need so tried:
<%if(request.getParameter("birthDateMonth")!=null){%>
<input type="text" name="calculatedElecSerYear" value"<%= birthDateMonth %>">
Then get the following error:
Syntax: "else Statement" inserted to complete IfThenElseStatement
Thanks for any help>
 
ernest fakudze
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mary,
Ok, there seems to be a lot of problems in your code. The main problem here is that *you do not understand the basics of Java* There are a lot of flaws in your control flow too. Here is how if-else works:
if(condition(s)) {
do statement
} else if(another condition) {
do another statememt
} else {
//All the other conditions above failed so we do
this one instead
} // end else
Also...
int cMonth=Integer.parseIntpassedBirthDateMonth );
SHOULD be..
int cMonth = Integer.parseInt((passedBirthDateMonth);
Read about wrapper classes to understand this one:

Here is what I suggest: Get the book "The java tutorial, A short course on the basics" and read it. You will pick the language up quickly from there.
Good luck.
Regards,
Ernie
 
mary morris
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, so if I have this working for a selected index, how would I get it to work for a text box?
<%
String passedBirthDateMonth = (String) request.getParameter("birthDateMonth");
if (passedBirthDateMonth==null) passedBirthDateMonth="0";
String birthMonths[] = {
"January" , "February" , "March" , "April", "May",
"June", "July", "August", "September", "October",
"November", "December"
};
int bM = Integer.parseInt( passedBirthDateMonth )-1;
%>
<select name="birthDateMonth" >
<OPTION >Month
<%
String mSelect1 = "";
for (int i=0;i<birthMonths.length;i++) {
if (i==bM) mSelect1 = "selected";
else mSelect1 = "";%>
<option value="<%= i %>"<%= mSelect1 %>><%= birthMonths[i] %></option><%
}%>
</select>
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never use if...else without opening and closing braces...{....}...
So if I were to do this I would.........

and
[code]
<%
String mSelect1 = "";
for (int i=0;i<birthMonths.length;i++) {
if (i==bM)
{
mSelect1 = "selected";
}
else
{
mSelect1 = "";
}%>
<option value="<%= i %>" <%= mSelect1 %> >
<%= birthMonths[i] %>
</option>
<% } // end for loop %>
Seems familiar code to me.....
- satya
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!