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" />
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.
Joined: Nov 03, 2008
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.
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.