Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkbox-once clicked-always sends the value as true

 
Nidhig Gupta
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am facing the following issue with checkbox in my code:
I have a checkbox in my jsp. I have some validations on some field based on the value of this checkbox. Now once i check the checkbox, it always returns the value as true. On page reload(i.e. on failure of some valiadtion, when the same pafe is reloaded) it diplays the checbox as checked onl though i have unchecked the checkbox and then submitted the page.
This happens only once i checked the checkbox. everything goes fine till i dont check the checkbox.

Below given is the code of jsp:
<nested:checkbox name="CreateCustomerForm" value="true" property="notProvHomePhone" /> <bean:message key="createcustomer.not.provided" />
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most browsers will keep check boxes checked when the page is refreshed. If you do not want that to be the case, you need to create a function with window.onload that takes the checkbox and sets the checked to be false.

Eric
 
Nidhig Gupta
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The requirement is to set the value to false if not checked & to true if it is checked. But once we have checked the checkbox then it always passes on the true value. Now I dont know what to do.
What you suggested will always set it to false.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing will ever set it to false. If the checkbox is checked, its value (whatever it is) will be sent as part of the form submission. If it is not checked, no parameter will be sent for the checkbox. There is no way to change that.
 
Nidhig Gupta
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All what you need to do is that in the reset method of the form of your page, set yhe variable for your checkbox as false & then the checkbox will behave as normal.


public void reset(ActionMapping mapping, HttpServletRequest request) {
notProvHomePhone = false;
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic