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?
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)?
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.
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.
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.
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