Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
rubbery bacon. rubbery tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic