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

jsp checkbox value conversion  RSS feed

 
mudassir shahab
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi dudes...
input has been taken to a jsp file..
how can i convert value taken by checkboxes into integer as all the parameters are in String format...that is how can i convert string into integer
<input type="checkbox" name="C1" value="300">
futhermore how can i keep record or calculate which checkboxes are checked so that further calculation can be performed
 
Steve Leach
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer.parseInt(string) converts a string to an integer.
A check-box is a yes or no value though, so I don't see it being an issue.
Basically, if C1 != null then the C1 checkbox is checked, otherwise it is not.
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it depends how you are using the checkboxes i suppose as to how you do it. further to the reply above i suspect what you want is something along the lines of:-
int ic1;
String sc1 = request.getParameter("C1");
if(sc1 == null)
ic1 = 0;
else
icl = Integer.parseInt(sc1);
 
Lisa D'Aniello
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are performing the calculation in the same page that the fields are filled out in, it might be simpler to use a javascript. I don't have exact syntax in my head, but it would go something like this:
var chkArry(NumCheckBoxes);
for(var i=0;i < chkArry.length;i++)
{
if(document.getElementById("CK" & i).checked)
//assuming you name your check boxes CK0 - CK?
{
chkArry(i) = document.getElementById("CK" & i).value;
//place value into an array
}
}
or if not, then you could also name all of the checkboxes the same thing and the browser should store them as a comma delimited array then you could extract them using the split() function (I have only tried this on text boxes, using asp, so this last idea is a guess).
These are primitive solutions, but they have served me well in the past. Hope this helps,
Lisa M.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!