Reputation: 4141
i am trying to get values of checkboxes to insert them later on in database. It is ok that unchecked checkboxes will not be sent to my servlet but the problem that i have when cheking more than one checkboxe it returns just the first I'am doing like that im my JSP:
<td><input type=checkbox id=\""+i+"\" name=cbo value=<%=object.getNom()+ object.getPrenom() %> /> <%=object.getNom()+object.getPrenom()%></td>
And In the servlet the following:
String[] checkboxes = request.getParameterValues("cbo");
System.out.println("operators checked are:" + checkboxes[i]);
Like you see I want to get all the values checked. but if i check more than one only the first CB is shown in my servlet.
Thinks for help.
Upvotes: 1
Views: 2575
Reputation:
The request.getParameterValues()
returns an array of values for multiple parameters with the same name found in the request.
If your request is OK, and by that I mean action?cbo=val1&cbo=val2&cbo=val3
etc, then, after you submit the form to your servlet, checkboxes
should be ["val1", "val2", "val3"]
.
First check your request.
And one question: the following is in a loop, right?
System.out.println("operators checked are:" + checkboxes[i]);
Upvotes: 3
Reputation: 5845
Give the same id instead of a dynamic one, on click call a javascript function. Here you'll get an array if you do a getElementByID()
.
Set this array into a hidden form variable and access it in your action.
Upvotes: 0