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


Groups > comp.lang.javascript > #22574 > unrolled thread

Default values of checkboxes in forms

Started byjonas.thornvall@gmail.com
First post2014-01-11 23:05 -0800
Last post2014-01-12 09:25 +0000
Articles 15 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#22574 — Default values of checkboxes in forms

Fromjonas.thornvall@gmail.com
Date2014-01-11 23:05 -0800
SubjectDefault values of checkboxes in forms
Message-ID<2fae46c4-b07c-48e6-a6b4-d7cdc597225a@googlegroups.com>
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.

If so what are the default values passed?

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> 

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

[toc] | [next] | [standalone]


#22575

Fromjonas.thornvall@gmail.com
Date2014-01-11 23:24 -0800
Message-ID<26361713-4ab5-4df3-9cf4-3f293e53d2ff@googlegroups.com>
In reply to#22574
Den söndagen den 12:e januari 2014 kl. 08:05:47 UTC+1 skrev jonas.t...@gmail.com:
> 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.
> 
> 
> 
> If so what are the default values passed?
> 
> 
> 
> 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> 
> 
> 
> 
> So does primen get a value by default when "p" checked and unchecked?

There seem to be a thousand convoluted answers on the net to this question?

if ( parent.menu.document.getElementById('p').checked){

do something?
}

[toc] | [prev] | [next] | [standalone]


#22576

Fromjonas.thornvall@gmail.com
Date2014-01-11 23:43 -0800
Message-ID<548b3877-55d8-4daa-baa6-672d4978c617@googlegroups.com>
In reply to#22575
Den söndagen den 12:e januari 2014 kl. 08:24:01 UTC+1 skrev jonas.t...@gmail.com:
> Den söndagen den 12:e januari 2014 kl. 08:05:47 UTC+1 skrev jonas.t...@gmail.com:
> 
> > 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.
> 
> > 
> 
> > 
> 
> > 
> 
> > If so what are the default values passed?
> 
> > 
> 
> > 
> 
> > 
> 
> > 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> 
> 
> > 
> 
> > 
> 
> > 
> 
> > So does primen get a value by default when "p" checked and unchecked?
> 
> 
> 
> There seem to be a thousand convoluted answers on the net to this question?
> 
> 
> 
> if ( parent.menu.document.getElementById('p').checked){
> 
> 
> 
> do something?
> 
> }

I attached an id to the name in form, but the code will not run.
An example of how you fetch checked/unchecked from a form?

Should not the below work?

if (parent.menu.document.check.getElementById('p').checked){
 printprime(); 
}

This is my form but the above code totally hang the script.

<FORM NAME=check onSubmit="parent.ulam.test(); return false;">
P<input id="p"  name="p" type="checkbox" checked="yes> 
</FORM>

[toc] | [prev] | [next] | [standalone]


#22577

Fromjonas.thornvall@gmail.com
Date2014-01-11 23:58 -0800
Message-ID<a2ea0b02-d30d-48a7-9fda-a5f5d1f54501@googlegroups.com>
In reply to#22576
Den söndagen den 12:e januari 2014 kl. 08:43:48 UTC+1 skrev jonas.t...@gmail.com:
> Den söndagen den 12:e januari 2014 kl. 08:24:01 UTC+1 skrev jonas.t...@gmail.com:
> 
> > Den söndagen den 12:e januari 2014 kl. 08:05:47 UTC+1 skrev jonas.t...@gmail.com:
> 
> > 
> 
> > > 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.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > If so what are the default values passed?
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 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> 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > So does primen get a value by default when "p" checked and unchecked?
> 
> > 
> 
> > 
> 
> > 
> 
> > There seem to be a thousand convoluted answers on the net to this question?
> 
> > 
> 
> > 
> 
> > 
> 
> > if ( parent.menu.document.getElementById('p').checked){
> 
> > 
> 
> > 
> 
> > 
> 
> > do something?
> 
> > 
> 
> > }
> 
> 
> 
> I attached an id to the name in form, but the code will not run.
> 
> An example of how you fetch checked/unchecked from a form?
> 
> 
> 
> Should not the below work?
> 
> 
> 
> if (parent.menu.document.check.getElementById('p').checked){
> 
>  printprime(); 
> 
> }
> 
> 
> 
> This is my form but the above code totally hang the script.
> 
> 
> 
> <FORM NAME=check onSubmit="parent.ulam.test(); return false;">
> 
> P<input id="p"  name="p" type="checkbox" checked="yes> 
> 
> </FORM>

I also tried this approach skipping the form just go for the element byte id, but it does not work.

var testar=parent.menu.document.getElementById('p');
         
         if(testar==checked) printprime();

Now code runs but i can not call printprime(); 

And also tried this if testar turn out to be string

         var testar=parent.menu.document.getElementById('p');
         if(testar=="checked") printprime();   

[toc] | [prev] | [next] | [standalone]


#22579

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-01-12 09:40 +0100
Message-ID<XnsA2B36270A6918eejj99@194.109.133.133>
In reply to#22577
jonas.thornvall@gmail.com wrote on 12 jan 2014 in comp.lang.javascript:

>> P<input id="p"  name="p" type="checkbox" checked="yes> 
> 

You are missing the closing quote of checked:

... checked="yes">

Try:

<form 
onsubmit =
'alert(this.a.checked+"\n"+
this.b.checked+"\n"+
this.c.checked+"\n"+
this.d.checked);
return false;'>
<input name = 'a' type = 'checkbox' checked><br>
<input name = 'b' type = 'checkbox' checked = 'checked'><br>
<input name = 'c' type = 'checkbox' checked = 'blue'><br>
<input name = 'd' type = 'checkbox' ><br>
<input type='submit'>
</form>

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#22581

Fromjonas.thornvall@gmail.com
Date2014-01-12 01:58 -0800
Message-ID<0ac12068-c3ea-45e1-99a4-a2e479bf2246@googlegroups.com>
In reply to#22579
Den söndagen den 12:e januari 2014 kl. 09:40:37 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 12 jan 2014 in comp.lang.javascript:
> 
> 
> 
> >> P<input id="p"  name="p" type="checkbox" checked="yes> 
> 
> > 
> 
> 
> 
> You are missing the closing quote of checked:
> 
> 
> 
> ... checked="yes">
> 
> 
> 
> Try:
> 
> 
> 
> <form 
> 
> onsubmit =
> 
> 'alert(this.a.checked+"\n"+
> 
> this.b.checked+"\n"+
> 
> this.c.checked+"\n"+
> 
> this.d.checked);
> 
> return false;'>
> 
> <input name = 'a' type = 'checkbox' checked><br>
> 
> <input name = 'b' type = 'checkbox' checked = 'checked'><br>
> 
> <input name = 'c' type = 'checkbox' checked = 'blue'><br>
> 
> <input name = 'd' type = 'checkbox' ><br>
> 
> <input type='submit'>
> 
> </form>
> 
> 
> 
> -- 
> 
> Evertjan.
> 
> The Netherlands.
> 
> (Please change the x'es to dots in my emailaddress)

Well what i really just want to do is to look if the box is checked or not, first i thought one could use the default "value" parameter/attribut to check if checked, but as someone pointed out it just hold the value "on".

I read one should us elementById, but i really have no idea howto fetch the value. I did remove the form around the checkbox, and sat "id" into the input type as parameter to check instead of value.

But it just do not work, it could be that i am using frameset. But i have no problems with forms, so i can not see why it should present a problem.

I've tried
if (parent.menu.document.check.getElementById('p').checked){ 
 printprime(); 
} 
also tried without form "check"
if (parent.menu.document.getElementById('p').checked){ 
 printprime(); 
} 

And it do not work, then i thought try to first Catch it into a variabel, but it just not working.

var testar=parent.menu.document.getElementById('p'); 
         if(testar=="checked") printprime(); 

[toc] | [prev] | [next] | [standalone]


#22582

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-01-12 17:50 +0100
Message-ID<XnsA2B3B56EEFAB0eejj99@194.109.133.133>
In reply to#22581
jonas.thornvall@gmail.com wrote on 12 jan 2014 in comp.lang.javascript:
> Den söndagen den 12:e januari 2014 kl. 09:40:37 UTC+1 skrev Evertjan.:
>> jonas.thornvall@gmail.com wrote on 12 jan 2014 in comp.lang.javascript:

>> > P<input id="p"  name="p" type="checkbox" checked="yes> 
>> You are missing the closing quote of checked:
>> ... checked="yes">

Did you correct for this blatant error, Jonas?

>> Try:
>> 
>> <form 
>> onsubmit 
>> 'alert(this.a.checked+"\n"+
>> this.b.checked+"\n"+
>> this.c.checked+"\n"+
>> this.d.checked);
>> return false;'>
>> <input name = 'a' type = 'checkbox' checked><br>
>> <input name = 'b' type = 'checkbox' checked = 'checked'><br>
>> <input name = 'c' type = 'checkbox' checked = 'blue'><br>
>> <input name = 'd' type = 'checkbox' ><br>
>> <input type='submit'>
>> </form>

Did you try this code, Jonas?

> Well what i really just want to do is to look if the box is checked or
> not, 

The above code will lead the way.

Do not try to do too much at once, like assessing the element on another 
page. First access the ellement using JS on the same page.

If that works, try accessing a random element, say a <div> on another page.

> first i thought one could use the default "value"
> parameter/attribut to check if checked, but as someone pointed out it
> just hold the value "on". 

Is that so? 

Methinks not. The "on" only appears as you send the form.
With Chrome the result is "true" or "false", as shown with my code.
With other modern browsers it could be different, but I doubt that.

Try not to go by "as someone pointed out" but by testing for yourself.

> I read one should us elementById, but i really have no idea howto fetch
> the value. 

So again try it in a simple way, not on a checkbos but with:

<div id=x>This is the content of div x</div>

alert( document.getElementById('x').innerHTML );

And if this works, go to the child page and try:

alert( parent.document.getElementById('x').innerHTML );


> I did remove the form around the checkbox, and sat "id" into
> the input type as parameter to check instead of value. 
> 
> But it just do not work, it could be that i am using frameset. But i
> have no problems with forms, so i can not see why it should present a
> problem. 

You are still trying without purpose or logic below:

 
> I've tried
> if (parent.menu.document.check.getElementById('p').checked){ 

How could the parent have a menu as child, which has a document as a child?

How could a document have a child called check,
Are you using Internet explorer 3 from last century?

>  printprime(); 
>} 
> also tried without form "check"
> if (parent.menu.document.getElementById('p').checked){

Same objection, you should first find out how the DOM tree works.
 
>  printprime(); 
>} 
> 
> And it do not work, then i thought try to first Catch it into a
> variabel, but it just not working. 
> 
> var testar=parent.menu.document.getElementById('p'); 
>          if(testar=="checked") printprime(); 

Same objection "parent.menu.document"

You should build up your knowledge about the DOM of a single page
before endavouring on a quest with parent and child pages.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#22586

Fromjonas.thornvall@gmail.com
Date2014-01-12 22:52 -0800
Message-ID<2d59b041-54b1-4e0a-9cd9-e27347f6d168@googlegroups.com>
In reply to#22582
Den söndagen den 12:e januari 2014 kl. 17:50:08 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 12 jan 2014 in comp.lang.javascript:
> 
> > Den s�ndagen den 12:e januari 2014 kl. 09:40:37 UTC+1 skrev Evertjan.:
> 
> >> jonas.thornvall@gmail.com wrote on 12 jan 2014 in comp.lang.javascript:
> 
> 
> 
> >> > P<input id="p"  name="p" type="checkbox" checked="yes> 
> 
> >> You are missing the closing quote of checked:
> 
> >> ... checked="yes">
> 
> 
> 
> Did you correct for this blatant error, Jonas?
> 
> 
> 
> >> Try:
> 
> >> 
> 
> >> <form 
> 
> >> onsubmit 
> 
> >> 'alert(this.a.checked+"\n"+
> 
> >> this.b.checked+"\n"+
> 
> >> this.c.checked+"\n"+
> 
> >> this.d.checked);
> 
> >> return false;'>
> 
> >> <input name = 'a' type = 'checkbox' checked><br>
> 
> >> <input name = 'b' type = 'checkbox' checked = 'checked'><br>
> 
> >> <input name = 'c' type = 'checkbox' checked = 'blue'><br>
> 
> >> <input name = 'd' type = 'checkbox' ><br>
> 
> >> <input type='submit'>
> 
> >> </form>
> 
> 
> 
> Did you try this code, Jonas?
> 
> 
> 
> > Well what i really just want to do is to look if the box is checked or
> 
> > not, 
> 
> 
> 
> The above code will lead the way.
> 
> 
> 
> Do not try to do too much at once, like assessing the element on another 
> 
> page. First access the ellement using JS on the same page.
> 
> 
> 
> If that works, try accessing a random element, say a <div> on another page.
> 
> 
> 
> > first i thought one could use the default "value"
> 
> > parameter/attribut to check if checked, but as someone pointed out it
> 
> > just hold the value "on". 
> 
> 
> 
> Is that so? 
> 
> 
> 
> Methinks not. The "on" only appears as you send the form.
> 
> With Chrome the result is "true" or "false", as shown with my code.
> 
> With other modern browsers it could be different, but I doubt that.
> 
> 
> 
> Try not to go by "as someone pointed out" but by testing for yourself.
> 
> 
> 
> > I read one should us elementById, but i really have no idea howto fetch
> 
> > the value. 
> 
> 
> 
> So again try it in a simple way, not on a checkbos but with:
> 
> 
> 
> <div id=x>This is the content of div x</div>
> 
> 
> 
> alert( document.getElementById('x').innerHTML );
> 
> 
> 
> And if this works, go to the child page and try:
> 
> 
> 
> alert( parent.document.getElementById('x').innerHTML );
> 
> 
> 
> 
> 
> > I did remove the form around the checkbox, and sat "id" into
> 
> > the input type as parameter to check instead of value. 
> 
> > 
> 
> > But it just do not work, it could be that i am using frameset. But i
> 
> > have no problems with forms, so i can not see why it should present a
> 
> > problem. 
> 
> 
> 
> You are still trying without purpose or logic below:
> 
> 
> 
>  
> 
> > I've tried
> 
> > if (parent.menu.document.check.getElementById('p').checked){ 
> 
> 
> 
> How could the parent have a menu as child, which has a document as a child?
> 
> 
> 
> How could a document have a child called check,
> 
> Are you using Internet explorer 3 from last century?
> 
> 
> 
> >  printprime(); 
> 
> >} 
> 
> > also tried without form "check"
> 
> > if (parent.menu.document.getElementById('p').checked){
> 
> 
> 
> Same objection, you should first find out how the DOM tree works.
> 
>  
> 
> >  printprime(); 
> 
> >} 
> 
> > 
> 
> > And it do not work, then i thought try to first Catch it into a
> 
> > variabel, but it just not working. 
> 
> > 
> 
> > var testar=parent.menu.document.getElementById('p'); 
> 
> >          if(testar=="checked") printprime(); 
> 
> 
> 
> Same objection "parent.menu.document"
> 
> 
> 
> You should build up your knowledge about the DOM of a single page
> 
> before endavouring on a quest with parent and child pages.
> 
> 
> 
> -- 
> 
> Evertjan.
> 
> The Netherlands.
> 
> (Please change the x'es to dots in my emailaddress)

I finally managed to get it working using...
 if (parent.menu.document.getElementById('o').checked == true) { do something }


So it seem that the name of getElementById attribute is not name, not id but checked?

http://web.comhem.se/jonasth/prime0.5/main.html

[toc] | [prev] | [next] | [standalone]


#22591

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-01-13 11:40 +0100
Message-ID<XnsA2B476C6B92D7eejj99@194.109.133.133>
In reply to#22586
jonas.thornvall@gmail.com wrote on 13 jan 2014 in comp.lang.javascript:

> ... document.getElementById('o').checked ...
> 
> 
> So it seem that the name of getElementById attribute is not name, not id
> but checked? 

What do you mean by "name" of an attribute?

The parameter of getElementById() must be an unique id, 

To avoid any possible cross-browser inconsistancies,
better always test element.checked for true/false,
NOT for: ==='on' or === 1 or === 'checked' 

var elem = document.getElementById('myCheckbox')
//or var elem = document.getElementById('myRadio')

if (elem.checked) 
   alert('elem is checked')
else
   alert('elem is unchecked');

====

btw, what do you think will be returned here?
First try to imagine it by analizing the code, 
and then test it by applying it to a file:

============= test.html ================
<input type='checkbox' name='hi' id='lo' checked>

<script type='text/javascript'>
    alert(document.getElementById('lo').name);
    alert(document.getElementById('lo').checked);
    alert(document.getElementsByName('hi')[0].id);
</script>
========================================

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#22599

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-01-13 13:02 +0000
Message-ID<lb0o51$k2a$1@dont-email.me>
In reply to#22591
On Mon, 13 Jan 2014 11:40:34 +0100, Evertjan. wrote:

> btw, what do you think will be returned here?
> First try to imagine it by analizing the code,
> and then test it by applying it to a file:
> 
> ============= test.html ================
> <input type='checkbox' name='hi' id='lo' checked>
> 
> <script type='text/javascript'>
>     alert(document.getElementById('lo').name);
>     alert(document.getElementById('lo').checked);
>     alert(document.getElementsByName('hi')[0].id);
> </script>
> ========================================

I think this is a trick question. alert doesn't return a value.

I think the output of the three alerts will be:

First: The string value: "hi"
Second: The boolean value: true
Third: The string value: "lo"

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#22603

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-01-13 15:00 +0100
Message-ID<XnsA2B498B3A3C8Beejj99@194.109.133.133>
In reply to#22599
Denis McMahon <denismfmcmahon@gmail.com> wrote on 13 jan 2014 in 
comp.lang.javascript:

> On Mon, 13 Jan 2014 11:40:34 +0100, Evertjan. wrote:
> 
>> btw, what do you think will be returned here?
>> First try to imagine it by analizing the code,
>> and then test it by applying it to a file:
>> 
>> ============= test.html ================
>> <input type='checkbox' name='hi' id='lo' checked>
>> 
>> <script type='text/javascript'>
>>     alert(document.getElementById('lo').name);
>>     alert(document.getElementById('lo').checked);
>>     alert(document.getElementsByName('hi')[0].id);
>> </script>
>> ========================================
> 
> I think this is a trick question. alert doesn't return a value.

Okay, let's be tricky then:

I did not ask for the output of the alert()s.

> I think the output of the three alerts will be:
> 
> First: The string value: "hi"
> Second: The boolean value: true
> Third: The string value: "lo"

The output of the script consists of 3 alert popup windows 
containing as variable text:

hi
true
lo

however the second one, "true", might be dependent on the
language setting of the browser or the OS.

Luckily that is not the case with my Dutch setting in W8.1 + Google Chrome,
so perhaps it is not as bad as in Excel VBA, where in stead of "FALSE" one 
must use "ONWAAR" [= untrue].

============================

Let's go back to the OQ, the "checked" defaults.

I would prefer not to call that an "attribute",
but rather a "property" of both the index-radio 
and index-checkbox elements. 

If this property is false, the element is not "set",
if true it is set. 

writing the property:
Anything other than false will set the element

reading the property:
This will return true or false. 

Even if it was set by:

myElement.checked = 'hazyBlueGrayish';

it will stil return true:

var result = myElement.checked;

The form-submit value when true is "on",
when false, it just is not submitted,
submitting to some pityfull last century idea, 
making same-name submissions impossible,
while easily enumerable in the DOM by javascript.

Better take all this not as a dogmatic truth, 
but as something to be confirmed by your own testing. 

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#22589

Fromjonas.thornvall@gmail.com
Date2014-01-13 01:28 -0800
Message-ID<afcdae0e-607c-4e92-b098-5105b718bb1c@googlegroups.com>
In reply to#22582
Den söndagen den 12:e januari 2014 kl. 17:50:08 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 12 jan 2014 in comp.lang.javascript:
> 
> > Den s�ndagen den 12:e januari 2014 kl. 09:40:37 UTC+1 skrev Evertjan.:
> 
> >> jonas.thornvall@gmail.com wrote on 12 jan 2014 in comp.lang.javascript:
> 
> 
> 
> >> > P<input id="p"  name="p" type="checkbox" checked="yes> 
> 
> >> You are missing the closing quote of checked:
> 
> >> ... checked="yes">
> 
> 
> 
> Did you correct for this blatant error, Jonas?

Yes and actually the browsers can handle it without paragraphs.

> 
> 
> >> Try:
> 
> >> 
> 
> >> <form 
> 
> >> onsubmit 
> 
> >> 'alert(this.a.checked+"\n"+
> 
> >> this.b.checked+"\n"+
> 
> >> this.c.checked+"\n"+
> 
> >> this.d.checked);
> 
> >> return false;'>
> 
> >> <input name = 'a' type = 'checkbox' checked><br>
> 
> >> <input name = 'b' type = 'checkbox' checked = 'checked'><br>
> 
> >> <input name = 'c' type = 'checkbox' checked = 'blue'><br>
> 
> >> <input name = 'd' type = 'checkbox' ><br>
> 
> >> <input type='submit'>
> 
> >> </form>
> 
> 
> 
> Did you try this code, Jonas?

It seem name is not the way to go, now i use id and look for ElementById 
which i guess is an object with an (boolean?) attribute, it is some what confusing because in all examples.

They write  if (parent.menu.document.getElementById('o').checked){ *do something*}

And i never got it to work, so it may be wrong, or the attribute actually not a boolean in the ordinary sense.

What does work is.

  if (parent.menu.document.getElementById('o').checked == true) { do something } 
 
> 
> > Well what i really just want to do is to look if the box is checked or
> 
> > not, 
> 
> 
> 
> The above code will lead the way.
> 
> 
> 
> Do not try to do too much at once, like assessing the element on another 
> 
> page. First access the ellement using JS on the same page.
> 
> 
> 
> If that works, try accessing a random element, say a <div> on another page.
> 
> 
> 
> > first i thought one could use the default "value"
> 
> > parameter/attribut to check if checked, but as someone pointed out it
> 
> > just hold the value "on". 
> 
> 
> 
> Is that so? 
> 
> 
> 
> Methinks not. The "on" only appears as you send the form.
> 
> With Chrome the result is "true" or "false", as shown with my code.
> 
> With other modern browsers it could be different, but I doubt that.
> 
> 
> 
> Try not to go by "as someone pointed out" but by testing for yourself.
> 
> 
> 
> > I read one should us elementById, but i really have no idea howto fetch
> 
> > the value. 
> 
> 
> 
> So again try it in a simple way, not on a checkbos but with:
> 
> 
> 
> <div id=x>This is the content of div x</div>
> 
> 
> 
> alert( document.getElementById('x').innerHTML );
> 
> 
> 
> And if this works, go to the child page and try:
> 
> 
> 
> alert( parent.document.getElementById('x').innerHTML );
> 
> 
> 
> 
> 
> > I did remove the form around the checkbox, and sat "id" into
> 
> > the input type as parameter to check instead of value. 
> 
> > 
> 
> > But it just do not work, it could be that i am using frameset. But i
> 
> > have no problems with forms, so i can not see why it should present a
> 
> > problem. 
> 
> 
> 
> You are still trying without purpose or logic below:
> 
> 
> 
>  
> 
> > I've tried
> 
> > if (parent.menu.document.check.getElementById('p').checked){ 
> 
> 
> 
> How could the parent have a menu as child, which has a document as a child?
> 

I Think this is correct i work in a frameset and called main with the Childs canvas and menu. When i call the canvas from menu or menu from canvas, on Always have to go via the parent frame (main.html)


> 
> How could a document have a child called check,
> 
> Are you using Internet explorer 3 from last century?

I do not recall how to use div instead of frameset so one go with the Tools one have...


> 
> >  printprime(); 
> 
> >} 
> 
> > also tried without form "check"
> 
> > if (parent.menu.document.getElementById('p').checked){
> 

That is the example shown in all pages, but it does not work. 
Now i use  
if (parent.menu.document.getElementById('o').checked == true) { do something } 

> 
> Same objection, you should first find out how the DOM tree works.
> 
>  
> 
> >  printprime(); 
> 
> >} 
> 
> > 
> 
> > And it do not work, then i thought try to first Catch it into a
> 
> > variabel, but it just not working. 
> 
> > 
> 
> > var testar=parent.menu.document.getElementById('p'); 
> 
> >          if(testar=="checked") printprime(); 
> 
> 
> 
> Same objection "parent.menu.document"
> 
> 
> 
> You should build up your knowledge about the DOM of a single page
> 
> before endavouring on a quest with parent and child pages.
> 
> 
> 
> -- 
> 
> Evertjan.
> 
> The Netherlands.
> 
> (Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#22590

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-01-13 11:10 +0100
Message-ID<XnsA2B471BABB49Ceejj99@194.109.133.133>
In reply to#22589
jonas.thornvall@gmail.com wrote on 13 jan 2014 in comp.lang.javascript:

>> >> > P<input id="p"  name="p" type="checkbox" checked="yes> 
>> 
>> >> You are missing the closing quote of checked:
>> 
>> >> ... checked="yes">
>> 
>> 
>> 
>> Did you correct for this blatant error, Jonas?
> 
> Yes and actually the browsers can handle it without paragraphs.

If you use an opening quote, you should use a closing quote.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#22578

From"Jukka K. Korpela" <jkorpela@cs.tut.fi>
Date2014-01-12 10:37 +0200
Message-ID<latk91$cma$1@dont-email.me>
In reply to#22574
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/

[toc] | [prev] | [next] | [standalone]


#22580

FromTim Streater <timstreater@greenbee.net>
Date2014-01-12 09:25 +0000
Message-ID<120120140925002064%timstreater@greenbee.net>
In reply to#22574
In article <2fae46c4-b07c-48e6-a6b4-d7cdc597225a@googlegroups.com>,
<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.
> 
> If so what are the default values passed?
> 
> 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> 
> 
> So does primen get a value by default when "p" checked and unchecked? 

Why don't you test it and see what you get.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web