• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

getting checkbox value even when unchecked

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear peeps,
I have a problem with getting checkbox value.
I have a list of checkbox
and I need to get the value of checkbox
'1' when checked, and '2' when unchecked.

But as I know, checkbox deliver their value only when it is checked.
How can I approach this problem?
 
Sheriff
Posts: 67756
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
"ch moon", please check your private messages for an important administrative matter.
 
Bear Bibeault
Sheriff
Posts: 67756
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
As you seem to already know, checkboxes will only submit a value when they are checked. There is no way to change this behavior.

You'll need to handle this on the server, perhaps by providing a default value when no value is submitted.

Or, perhaps you can consider using a set of radio buttons in place of the checkbox.
[ October 20, 2008: Message edited by: Bear Bibeault ]
 
changhyun moon
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your guide and right reply,
I thought about it.
However, I need to set the values with proper list already existed in the server.
I believed that checking checked or unchecked is waste of process while I set the list.
Is there anyway in the javascript way to control unchecked value to be delivered as '2'(as I described on the question)?
 
Bear Bibeault
Sheriff
Posts: 67756
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
I repeat:

There is no way to change this behavior.


You can consider switching to radio buttons, as I suggested, or you could create a hidden element to submit an appropriate value. But there is no way to force an unchecked checkbox to return a value when unchecked.
 
Sheriff
Posts: 28435
103
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by changhyun moon:
I believed that checking checked or unchecked is waste of process while I set the list.

The amount of time spent based on unsupported beliefs often amazes me. Just write the if-statement already. There's no reason to look for workarounds for an if-statement.
 
Bear Bibeault
Sheriff
Posts: 67756
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

Originally posted by Paul Clapham:
The amount of time spent based on unsupported beliefs often amazes me. Just write the if-statement already. There's no reason to look for workarounds for an if-statement.


Quoted for truth.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use Java script to get the values and put the values in session. when next time page loads or do anything its still in session and then you can put logic to again change/retrieve the value
 
Bear Bibeault
Sheriff
Posts: 67756
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
"in search for java", please check your private messages for an important administrative matter.
 
Bear Bibeault
Sheriff
Posts: 67756
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

Originally posted by in search for java:
You can use Java script to get the values and put the values in session.

No, you can't. JavaScript has no access to the session whatsoever.
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic