This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkbox

 
trinadh reddy
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
trinadh reddy
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you send me simple code for this scenario for unchecking as it is urgent for me
 
Gareth Faulkner
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't you mean there must be only one input with a NAME of myCheckbox
 
Gareth Faulkner
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, my mistake!

Gareth
 
trinadh reddy
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic