[whatwg] non-checked checkbox posting success?

Ric Hardacre ric at hardacre.org
Tue Jul 25 02:39:23 PDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Alexey Feldgendler wrote:
> On Mon, 24 Jul 2006 22:59:07 +0700, Ric Hardacre <whatwg at cycloid.f9.co.uk> wrote:
> 
>> When using checkboxes in forms i find myself doing this
> 
> I don't see how this
> 
>> <input type="checkbox" name="foo" value="true">
>> <input type="hidden" name="foo" value="false">
>>
>> if( checkbox.value == "false" )then
>> 	bSomeBool = false;
>> else	
>> 	bSomeBool = true;
> 
> is in any way better than this
> 
> <input type="checkbox" name="foo">
> 
> if (checkbox.value == "checked") then
> 	bSomeBool = true;
> else	
> 	bSomeBool = false;
> 
> IMHO, the former example adds neither semantic depth nor programming convenience compared to the latter.
> 

My example is server-side psudeo code, not client side javascript. When
posting back an unchecked checkbox you get nothing on the server: no
indication that a checkbox even exists in the form just posted. In many
(if not most) use cases you are probably expecting a checkbox because
you put it there. Sometimes however you need to rely on form field
discovery (sanity checks and validation applied as needed, naturally).

For example, using the repeater HTML5 setup or DOM manipulation, the
user might be able to manually add fields to a form, if one of those
fields is a checkbox it will get lost in the postback. example:

Employees (Repeater)
<hr>
Is Manager? <input name="cbStatus12" type="checkbox" value="Manager"
ucvalue="Employee">
Name <input name="txName12" type="text" >

if we don't have a "ucvalue" we need to infer the value of the checkbox:

function getManagerValue( value )
{
	if( value=="Manager" )
		return "Manager";
	else
		return "Employee";
}

if you have many choices like this you will build up a body of redundant
code which also presents maintainability issues: what if the values
change? you have to change the relevant source too. What about
internationalisation? etc.

Again, i understand that in certain instances (including, i humbly
admit, the example i just gave) a two-option select or two radio buttons
might be better or more appropriate, and allow room for more options in
the future. but sometimes you do just need "on" and "off", "yes" and
"no", "true" and "false" and the checkbox is - by design - a logical
expressor of these binary choices.

Ric Hardacre
http://www.cyclomedia.co.uk/







-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFExebLdf0h6ZthGgIRAlbfAKC/mb5zmEPxElhmnIOz+Q29fbyLWQCgmjvn
/W9G8jqeTVBw9aFozpuupoQ=
=OGRA
-----END PGP SIGNATURE-----



More information about the whatwg mailing list