wood burning stoves 2.0*
The moose likes JSP and the fly likes checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "checkbox" Watch "checkbox" New topic
Author

checkbox

trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
in jsp i have various checkboxes
when i check it the values are updated to the xml file.
but when iam unchecking the checkboxes no action is occuring.
can you tell me the solution for this
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
The problem is that if a checkbox is unchecked, the value does not get passed to the server on submition. Eg:

<input type="checkbox" name="myCheckbox">

If this box is unchecked,
request.getParameter("myCheckbox") will return null, as if the control is not even on the page.

You have to explicitly check if your parameter returns a null value in order to know if the checkbox is unchecked.


We're doomed!!<br />Yay!!!<br />No that's bad Girr!!<br />Yay!!!
trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
can you send me simple code for this scenario for unchecking as it is urgent for me
Gareth Faulkner
Greenhorn

Joined: Oct 29, 2004
Posts: 22
Code in HTML

<input type="checkbox" name="myCheckbox">


Code in Servlet

boolean myCheckboxChecked = false;
if (request.getParameter("myCheckbox") != null) {
myCheckboxChecked = true;
}

For this code to work, there must be only one input with a value of myCheckbox.

Gareth
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
Don't you mean there must be only one input with a NAME of myCheckbox
Gareth Faulkner
Greenhorn

Joined: Oct 29, 2004
Posts: 22
Yes, my mistake!

Gareth
trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
I have a scenario. in jsp there are number of checkboxes.when you check some of them the checkedvalues are updated to the xml file.up to this no problem.but when you deselect some of the checkboxes those values are not updated to the xml file


String[] checkedValues= request.getParameterValues("checkit");
here checkit is the name of the checkbox.
can You tell me the solution.
trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
in jsp i have various checkboxes .when i check the values are updated to the xml file.up to this no problem.
but when iam uncheking the values are not updated to the xml file
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: checkbox