Hi I have problem in saving checkbox values to the database. I have a JSP form which has some 18 checkboxes in it. The form is like providing permissions to particular usergroup. Some group are allowed to use some permissions but say an administrator has chance to work on all modules. Once the check boxes are checked, value 1 should get saved in database either through JSP code or servlets code. We are actually using servlet for database connectivity like adding new record to databse, saving the record etc. How do i trap whether the check boxes are checked or not ? After trapping, how do pass the value 0 or 1 to database based on whether checked or unchecked. SO now how i go about it ? i.e., saving the checked check box value in databse. ANd also, when i select a particular group, i need to display all the checkboxes + checked checkboxes for which that group is given permissions Here is a sample of code which i have written:
Do help me in this issue as early as possible. Eagerly waiting fr reply thanks in advance regards kavitha
try out this, request.getParametervalues("your checkbox name") this will give you a string array of check box values that are selected. in your case 1,2,3, .... then do the processing based on the selected values. Pradheep
posted 15 years ago
Thanks for ur reply, I need to tell u one more thing, i am new to both JSP and servlets. so i need to know where i should put the code u told i.e., in JSP page or in servlet or in script. I tried the same code in JSP with <% tags but it didnt work. So do tell me as to where i should put the code thanks
Welcome to the JavaRanch! We don't have many rules around the 'Ranch, but we do require your display name to follow the JavaRanch Naming Policy. You can change it here.
Thanks! and welcome to the JavaRanch!
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
posted 15 years ago
Hi Welsh, I am able to trap the checked items in the servlet. Thanks a lot. Now how do i save these into the database. As i have already said i have 5 rows and each row has 3 columns with 1 check box in each column. Suppose the user clicks 1st row 2nd col, 2nd row 3rd adn 4th column, 5th row 1st, 2nd & 3rd columns. In the database also the rows stands for rows and 3 columns stands fr columns (fields). Can anyone advice me as to how to achieve at this. I want to store in the database as 1 fr check boxes clicked and in all other cases as 0. In the database i want a format like this ------------------------------------------------ GrpName Moduleid aR eR dR ------------------------------------------------ S1 M1 1 0 0 S1 M2 0 1 1 S1 M3 1 1 1 S2 M1 0 0 1 S2 M2 1 0 1 S2 M3 1 0 1 .............. wherein ar, er, dr stands for colums as check boxes. When it is checked, 1 is stored otherwise 0. How od i write insert query fr that? sorry