• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with request.getParameter() on checkbox field....

 
Gabriel Fox
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a list of checkboxes i.e.
<input type="checkbox" name="myName" value="myValue">
If X number of checkboxes are rendered on my JSP
with unique name and value attributes.
How do i retrieve the values assigned to the
name or value attributes of the "checked/ticked" checkboxes on the server ,when the form is submitted, using request.getParameter("xxx") or otherwise.
All ideas are welcomed.
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless I am misunderstood your question, I believe you already have the answer. By your statement if you have x number of checkboxes and each checkbox has a unique name then you should be able to access the value using the getParameter(java.lang.String name) of the ServletRequest interface. If the parameter has more than one value use the getParameterValues(java.lang.String name) method.
For example:
<imput type=checkbox name=box1 value=1>
<input type=checkbox name=box2 value=2>
<input type=checkbox name=box3 value=3>
// will return value for box2 if checked otherwise
// will return null if parameter does not exist
String value = request.getParameter("box2")
Or another example:
<imput type=checkbox name=box value=1>
<input type=checkbox name=box value=2>
<input type=checkbox name=box value=3>
// will return all values for box or null if
// parameter does not exist
String[] values = request.getParameterValues("box")
I hope this helps.
cj
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!