开发者

how to get values from a group ofcheckboxes?

i am trying to get values of checkboxes to insert them later on in database. It is ok that unchecked checkboxes w开发者_C百科ill 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.


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]);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜