• 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

jsp checkbox value conversion

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic