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.
-
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.dgvid– dgvid2012-07-18 13:53:32 +00:00Commented 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 calldr_mak– dr_mak2012-07-18 14:01:26 +00:00Commented Jul 18, 2012 at 14:01
Add a comment
|
1 Answer
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.
5 Comments
dr_mak
Wat do i pass as data in my request from the ajax function in js.
Quentin
You just have multiple key/value pairs in the data with the same key name.
dr_mak
Can u tell me the code to be used in ajax call. I m a beginner.
Quentin
Writing a complete guide on how to build an Ajax request is out of scope for StackOverflow.
dr_mak
thanks... i did it this way only... and sorry for asking the code.