views:

214

answers:

2

Does anyone have a no JavaScript way to make HTML checkbox still submit a value? As in if you check it the form submission will include a value A but if it is uncheck it still contains a value B?

While I figure there isn't any way, I'm working on a site which needs to still be function when JS is off, and this would be ideal.

A: 

You might be able to do it by having a hidden form element with the same name. However, different browsers may treat the priority of which one gets submitted (if the checkbox is checked) differently, so at best, it's a hacky solution.

waiwai933
+4  A: 

HTML checkboxes aren't supposed to work that way. If you check the checkbox, the definied parameter name=value pair will be sent. If you uncheck it, it will not be sent. In the server side you just have to check the presence of the parameter name (or value in case of multiple checkboxes in a named group) in the parameter map and handle accordingly. If present, then it's checked. If absent, then it's not checked. Simple as that. You already know the "unchecked value" in the server side.

BalusC