0

I have a number of check boxes on my JSP page. I need to pass ids of all the check boxes to my servlet so that i can perform some database operations. I thought that i can create an array in my javascript function placed in a different .js file which would store these ids and then pass the array to my servlet. But i m not able to figure out how to apply this concept.

2
  • Can you add a little more detail about what you have tried so far? If possible, post a small code sample. The answer will depend, among other things, on whether your checkbox values are to be submitted as part of a form or are being passed via an AJAX call, so be sure to address that. Commented Jul 18, 2012 at 13:53
  • i havn't really worked on this problem in my project. But i have used ajax calls in rest of the functions. i am confused about this. what should i pass on as data in the ajax call Commented Jul 18, 2012 at 14:01

1 Answer 1

2

This type of problem is normally approached with

  <input type="checkbox" name="foo" value="1">
  <input type="checkbox" name="foo" value="2">
  <input type="checkbox" name="foo" value="3">
  <input type="checkbox" name="foo" value="4">

And then

String values[]=req.getParameterValues("foo");

Which gives you an array of all the checked values.

Sign up to request clarification or add additional context in comments.

5 Comments

Wat do i pass as data in my request from the ajax function in js.
You just have multiple key/value pairs in the data with the same key name.
Can u tell me the code to be used in ajax call. I m a beginner.
Writing a complete guide on how to build an Ajax request is out of scope for StackOverflow.
thanks... i did it this way only... and sorry for asking the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.