this question has answer here:
i have values of checkbox , click delete values , type must sent servlet called deleteservlet. please me how send values?
<html> <head> <script type="text/javascript"> function get_check_value(chkbox){ if(chkbox.checked){ var values=chkbox.value; //send values servlet } } function dodelete(theclick){ var type=theclick; //send type servlet alert(type); } </script> </head> <%string user=request.getparameter("users"); %> <body> <% string user[]=user.trim().split(" "); for(int i=0;i<user.length;i++){%> <center> <form name='list' action='adduserservlet'> <% out.println("<input type='checkbox' name='user" + + "' value='"+ user[i] + "' onclick='return get_check_value(this)'>" + user[i]+ "</input>" ); %> </form> <%}%> <input type="submit" value="add" name="b1" > <input type="submit" value="modify" name="b1"> <input type="submit" value="delete" name="b1" onclick="return dodelete(value)" > </center> </body> </html>
i tried "document.list.user.value" in alert box comes undefined object. send servlet tried following line nothing read
chk_val=chkbox.value; document.add.action = "adduserservlet?type=delete&name="+chk_val; document.add.submit();
you don't need javascript @ all.
just change code html form generated follows:
<form action="adduserservlet" method="post"> <input type="checkbox" name="user" value="1"> <input type="checkbox" name="user" value="2"> <input type="checkbox" name="user" value="3"> <input type="checkbox" name="user" value="4"> <input type="checkbox" name="user" value="5"> <input type="submit" name="b1" value="add"> <input type="submit" name="b1" value="modify"> <input type="submit" name="b1" value="delete"> </form>
(the checkbox value must unique user id)
then use request.getparametervalues()
in adduserservlet
:
string b1 = request.getparameter("b1"); if ("delete".equals(b1)) { string[] users = request.getparametervalues("user"); // ... }
the users
array contain checked values (1, 2, 3, 4 and/or 5).
Comments
Post a Comment