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


Groups > comp.lang.javascript > #15463

Re: radio buttons with. checkbox

From emf <emfril@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: radio buttons with. checkbox
Date 2012-08-20 09:05 -0400
Organization Aioe.org NNTP Server
Message-ID <k0tcfo$q8t$1@speranza.aioe.org> (permalink)
References <k0o75t$iac$1@speranza.aioe.org> <502fb66c$0$6212$ba4acef3@reader.news.orange.fr> <k0qpjr$6s8$1@speranza.aioe.org> <k0r30j$t06$1@speranza.aioe.org> <503226e3$0$6218$ba4acef3@reader.news.orange.fr>

Show all headers | View raw


On 2012-08-20 08:00 SAM wrote:
> Le 19/08/12 18:11, emf a écrit :
>> On 2012-08-19 09:30 emf wrote:
>>> On 2012-08-18 11:36 SAM wrote:
>>>> Le 18/08/12 16:03, emf a écrit :
>>>>> In my Spherical Triangle Calculator:
>>>>> I considered making the deg°min' a checkbox instead:
>>>>>
>>>>> https://files.nyu.edu/emf202/public/js/spherical2.html
>>>>
>>>>
>>>>                  if (using !== "r") {
>>>>                      a  = (a0 !== x)?  rad(a0)  : a0;
>>>>                      ab = (ab0 !== x)? rad(ab0) : ab0;
>>>
>>> I should have thought of that.
>>>
>>>>> but there are problems with the code. To begin with, if you click
>>>>> Radians, the degmin checkbox *is* disabled, but then when I click
>>>>> Clear
>>>>> while the Degrees is selected the degmin remains disabled.
>>>>
>>>>    <input type ="reset" onclick="dgmn.disabled=0" value="Clear">
>>>
>>> Thanks.
>>>>
>>>>   Also, I'd
>>>>> prefer if the radio buttons and the checkbox are outside the dataForm,
>>>>> so their settings won't change with Clear, but then when clicking
>>>>> Calculate, it should be able to tell the current status of the
>>>>> buttons/checkbox.
>>>>>
>>>>> spherical2 is more logical, but is there a straightforward way to make
>>>>> it work as it should?
>>>>
>>>> logical ... logical ... fast said !
>>>> deg°min' would have to be displayed only if degrees are checked, no ?
>>>
>>> Interesting idea. I've been changing the code to make it disappear
>>> instead of get disabled.
>>>
>>>>
>>>>> P.S. The defective code in spherical2 is:
>>>>
>>>> I allways get "invalid entry" ... !!!
>>>> What numbers could I enter ?
>>>
>>> Try for A, AB, B: 80, 100, 120 degrees or 1, 2, 3 radians. Or, more
>>> interesting, A, B, BC 80, 120, 76.33.
>>>
>>> Or even:
>>>
>>> A: Paris    48.75N 2.33E
>>> B: North Pole  90N
>>> C: New York 40.75N  -74W
>>>
>>> AB = 90 - 48.75 = 31.25
>>> B  = 74 + 2.33  = 76.33
>>> BC = 90 - 40.75 = 49.25
>>> CA = NY to Paris
>>> (and, or course, distance = CA * 40000 / 360 km)
>>>
>>>>   var using = "#°##.#'";
>>>>
>>>>   function inputOutput() {
>>>>      var format = document.dataForm.formats.value,
>>>>          degMin = document.dataForm.dgmn.checked;
>>>>      document.dataForm.dgmn.disabled = (format === 0);
>>>>      using = format === 0? "r" : degMin? "#°##.#'" : ".###°";
>>>>          }
>>>> ...
>>>>                  <label for="rads" style="padding-right:1em;">
>>>>                      <input type="radio" name="formats" id="rads"
>>>>                       value="0" onClick="inputOutput()";> Radians
>>>>                  </label>
>>>>                   <label for="degr" style="padding-right:1em;">
>>>>                       <input type="radio" name="formats" id="degr"
>>>>                        value="1" onClick="inputOutput()"; checked>
>>>> Degrees
>>>>                  </label>
>>>>                 <label for="dgmn2" style="padding-right:1em;">
>>>>                      <input type="checkbox" name="dgmn" id="dgmn2"
>>>>                        onClick="inputOutput()"> deg°min'
>>>>                  </label>
>>>
>>> The code doesn't work as expected but I'll work on it.
>>>
>>> emf
>>
>> (Continued)
>>
>> I couldn't understand very well your inputOutput() so simplified. I made
>> the deg°min' (within <span id="cgdgmn"></span>) disappear when radians
>> is clicked:
>>
>> https://files.nyu.edu/emf202/public/js/spherical2.html
>>
>> The code now is working OK, except that when it loads it gives this
>> error message:
>>
>> TypeError: document.getElementById("cbdgmn") is null
>
> I can't see that ..
>
> function inputOutput() {
>      var format = document.dataForm.formats,
>          n = format.length,
>          degMin = document.dataForm.dgmn.checked;
>      while(n--) if(format[n].checked) format=format[n].value;
>      document.dataForm.dgmn.parentNode.style.visibility = (format==0)?
>                                                           '' : 'hidden';
>      using = format == 0? "r" : degMin? "#°##.#'" : ".###°";
>          }
>
>> And I would prefer it by clicking Clear it didn't affect the radio
>> buttons and the checkbox...
>
> Il "Clear" is a reset button, clicking it must "reset" the whole code of
> the form ;-)

I believe that at last I can stop worrying with the code. I had started 
writing the program in QBasic some 10 years ago as an offshoot of a 
program that draws the globe, but had then encountered insurmountable 
then problems with the ambiguous cases (I an neither a professional 
mathematician nor a programmer) and had left it aside.

I explain the reset in another message.

After trial and error, I accepted your approach that inputOutput does 
not accept any parameters, but I get the status of the radioboxes and 
the checkbox in another way.

It seems that since the inputOutput function loads before the rest of 
the webpage, I had to write

if ((rads !== null) && (degr !== null) && (dgmn !== null)
   && (spanCheckbox !== null)) {
   ...
}
else {
     using = ".###°";
}

so that when first loading the webpage it would just initialize the 
using to a value corresponding the initial condition of the radio 
buttons and the checkbox. The error messages did not interfere with the 
program, but I do not like to get error messages. Then I though of 
substituting all these conditions with

if (using !== undefined) {
...
}
elseelse { using = ".###°"; }

which is simpler and up to the point; in the first run, there I just 
have to define using. The other elements are being taken care of by the 
html code.

Bye,

emf

-- 
It ain't THAT, babe! - A radical reinterpretation
https://files.nyu.edu/emf202/public/bd/itaintmebabe.html

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


Thread

radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-18 10:03 -0400
  Re: radio buttons with. checkbox SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-18 17:36 +0200
    Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-19 09:30 -0400
      Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-19 12:11 -0400
        Re: radio buttons with. checkbox SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-20 14:00 +0200
          Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-20 09:05 -0400
            Re: radio buttons with. checkbox SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-20 16:11 +0200
              Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-21 05:25 -0400
                Re: radio buttons with. checkbox Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-21 14:36 +0200
                Re: radio buttons with. checkbox SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-22 12:24 +0200
      Re: radio buttons with. checkbox SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-20 12:13 +0200
      Re: radio buttons with. checkbox Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-20 16:27 +0200
        Re: radio buttons with. checkbox SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-20 21:58 +0200
        Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-21 10:58 -0400
          Re: radio buttons with. checkbox Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-22 10:41 +0200
          Re: radio buttons with. checkbox "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-08-22 10:14 +0000
          Re: radio buttons with. checkbox SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-22 14:31 +0200
  Re: radio buttons with. checkbox Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-18 19:18 +0200
    Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-20 08:29 -0400
      Re: radio buttons with. checkbox Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-20 16:25 +0200
        Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-21 06:06 -0400
          Re: radio buttons with. checkbox Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-21 14:33 +0200
            Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-21 10:51 -0400
              Re: radio buttons with. checkbox Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-22 11:42 +0200
              Re: radio buttons with. checkbox SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-22 14:27 +0200
            Re: radio buttons with. checkbox Dr J R Stockton <reply1234@merlyn.demon.co.uk.invalid> - 2012-08-22 20:24 +0100
              Re: radio buttons with. checkbox Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-23 11:06 +0200
                Re: radio buttons with. checkbox Dr J R Stockton <reply1234@merlyn.demon.co.uk.invalid> - 2012-08-25 17:01 +0100
          Re: radio buttons with. checkbox Dr J R Stockton <reply1234@merlyn.demon.co.uk.invalid> - 2012-08-22 19:58 +0100
        Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-22 02:20 -0400
          Re: radio buttons with. checkbox Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-22 10:44 +0200
          Re: radio buttons with. checkbox SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-22 14:40 +0200
            Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-08-26 00:16 -0400
            Re: radio buttons with. checkbox emf <emfril@gmail.com> - 2012-09-03 07:19 -0400
    Re: radio buttons with. checkbox David Mark <dmark.cinsoft@gmail.com> - 2012-09-03 21:02 -0700
      Re: radio buttons with. checkbox Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-04 13:44 +0200
        Re: radio buttons with. checkbox David Mark <dmark.cinsoft@gmail.com> - 2012-09-04 06:00 -0700

csiph-web