Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #22578

Re: Default values of checkboxes in forms

From "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Newsgroups comp.lang.javascript
Subject Re: Default values of checkboxes in forms
Date 2014-01-12 10:37 +0200
Organization A noiseless patient Spider
Message-ID <latk91$cma$1@dont-email.me> (permalink)
References <2fae46c4-b07c-48e6-a6b4-d7cdc597225a@googlegroups.com>

Show all headers | View raw


2014-01-12 9:05, jonas.thornvall@gmail.com wrote:

> I know this is not strictly JavaScript, but i've tried to figure out
> if there is boolean default values for checked unchecked sent from a
> form checkbox to JavaScript when value not set.

Well, it is a JavaScript question in the sense that it deals with the 
correspondence between an HTML attribute of an element and a JavaScript 
property of the element node in the DOM. It has not been formally 
defined, but what HTML5 CR says about it describes the established 
browser behavior and can be regarded as the de facto standard, even 
though the CR in general is

It defines the checked property (or "IDL attribute" as it calls it) as 
having the truth value true or false according to the checkedness of the 
element:
http://www.w3.org/TR/html5/forms.html#dom-input-checked

> If so what are the default values passed?

Default in which sense? The initial values of the checkedness of a 
checkbox can be set with the checked HTML attribute or by setting the 
defaultChecked property. When the checked HTML attribute is absent, the 
default checkness is false, i.e. the element is initially unchecked. If 
the attribute is present, its value shall be either the empty string or 
the string "checked" (case-insensitively). Other values are defined to 
be non-conforming, but they, too, cause the default checkedness to be 
true. In a rather misleading manner, HTML5 CR calls attributes like this 
"Boolean attributes"; a better name would be "presence attributes": it 
is the presence of the attribute that matters, not its value (so that 
even checked="false" sets the default checkedness to true).

> In code i use this statement to Catch value.
>
> primen = parent.menu.document.check.p.value;
>
> And in HTML <FORM NAME=check onSubmit="parent.ulam.checked(); return
> false;"> P<input type="checkbox" name="p" checked="yes </FORM>

Huh? There are essential ingredients missing from the markup, and the 
markup is valid. Anyway, the value property of the checkbox here has the 
value "on" (a string consisting of the two letters "o" and "n"). Quite 
independently of its checkness. This is browser practice, being now 
standardized in HTML5. It isn't as paradoxical as it may sound, since 
the value is meant to be used only in name=value pairs sent as part of 
form data on submission, and such a pair is not included at all if the 
checkbox is not in the checked state.

> So does primen get a value by default when "p" checked and
> unchecked?

It gets the string value "on".

You should describe what you are really trying to achieve. I think I 
will not try to read through your discussion with yourself and with 
fullquoting to guess what the context and purpose really are. I will 
just say that what you should normally do in JavaScript when working 
with a checkbox is you use (read or write or both) the element's checked 
property, which has the truth values true and false.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Default values of checkboxes in forms jonas.thornvall@gmail.com - 2014-01-11 23:05 -0800
  Re: Default values of checkboxes in forms jonas.thornvall@gmail.com - 2014-01-11 23:24 -0800
    Re: Default values of checkboxes in forms jonas.thornvall@gmail.com - 2014-01-11 23:43 -0800
      Re: Default values of checkboxes in forms jonas.thornvall@gmail.com - 2014-01-11 23:58 -0800
        Re: Default values of checkboxes in forms "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-12 09:40 +0100
          Re: Default values of checkboxes in forms jonas.thornvall@gmail.com - 2014-01-12 01:58 -0800
            Re: Default values of checkboxes in forms "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-12 17:50 +0100
              Re: Default values of checkboxes in forms jonas.thornvall@gmail.com - 2014-01-12 22:52 -0800
                Re: Default values of checkboxes in forms "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-13 11:40 +0100
                Re: Default values of checkboxes in forms Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-13 13:02 +0000
                Re: Default values of checkboxes in forms "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-13 15:00 +0100
              Re: Default values of checkboxes in forms jonas.thornvall@gmail.com - 2014-01-13 01:28 -0800
                Re: Default values of checkboxes in forms "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-13 11:10 +0100
  Re: Default values of checkboxes in forms "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-01-12 10:37 +0200
  Re: Default values of checkboxes in forms Tim Streater <timstreater@greenbee.net> - 2014-01-12 09:25 +0000

csiph-web