aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes checkbox-once clicked-always sends the value as true Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "checkbox-once clicked-always sends the value as true" Watch "checkbox-once clicked-always sends the value as true" New topic
Author

checkbox-once clicked-always sends the value as true

Nidhig Gupta
Greenhorn

Joined: Nov 03, 2008
Posts: 5
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Nov 03, 2008
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61648
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nidhig Gupta
Greenhorn

Joined: Nov 03, 2008
Posts: 5
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;
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: checkbox-once clicked-always sends the value as true