This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Check Box

 
Ashok Kulkarni
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i have n number of check boxes in jsp, i have assigned ids for each checkbox
i want kown which one is selected and catch the values of checked ones
in servlet.can any one give soln for this..plsss
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashok,
I m not sure abt the use of id,but I have following option for your problem....
<input type="checkbox" name="chk1" value="1">
<input type="checkbox" name="chk1" value="2">
<input type="checkbox" name="chk1" value="3">
make sure names for all checkbox are same
And you can use request.getParameterValues() to chekc whihc one is selected as below
String s[]=request.getParameterValues("chk1");//chk1 is the name of chkbox
for(int i=0;i<s.length;++i)
out.println(s[i]);
Hope this helps
Cheers
Praful
 
Ashok Kulkarni
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx ,,,,
But i am getting Null pointer Exception
where i need to pass check box name through url ...
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you just need to put all check box and submit button in same form tag
<form>
<input type=...
...
..
<input type=submit value="hit me">
</form>
are you using any link for submitting your form ??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic