File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting checkbox value even when unchecked

 
changhyun moon
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ch moon", please check your private messages for an important administrative matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Pie
Posts: 20184
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
in search for java
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"in search for java", please check your private messages for an important administrative matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic