• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

checkbox-once clicked-always sends the value as true

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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" />
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
reply
    Bookmark Topic Watch Topic
  • New Topic