From: Geoff on
On Tue, 23 Mar 2010 19:29:22 -0400, Dr_Kral(a)nyc.rr.com.invalid wrote:


>Rather than use 'onfocus' use 'onclick' which mean that you act after the
>respondent has acted. For all the check boxes you use
>onclick='showhide17()'. Then the function looks at all the boxes and
>decides if the secondary question should be shown or not. In this case,
>since only one check box matters, it can be simplified like the example I
>gave last week.

K.

Thanks again for the helpful info - I have changed to using onclick()
at

http://www.micro-active.com/a-wm2/a-q-student-wm2.htm

Seem OK/better?!

Cheers

Geoff




>
>You need to consider what reload whenn some thing have been filled in.
>
>
From: Dr_Kral on
On Wed, 24 Mar 2010 00:51:01 +0000, Geoff <geoff(a)invalid.invalid> wrote in
<tcoiq59doulsdmrtis7t1uk2joc8baigp7(a)4ax.com>:

>Seem OK/better?!
Yes it does and much better.

Since JS use zero reference in numbering things, it usually better to do
the same since then natural loop (j=0;j<xx.length;j++) works well with the
id parameter as in document.getElementById('demo'+j)

You might try change the style of .visibleDiv to 'inline' rather than
'block'.


Since the conditions to be tested are only ONE check box at a time then one
can really have simpler code. For example:
++++
<p>Click the boxes<br>&nbsp;<br>
<input type="checkbox" name="hcm0" id="hcm0"> Box 0&nbsp;
<input type="checkbox" name="hcm1" id="hcm1"
onclick="document.getElementById('demo1').style.display=(this.checked)?'inline':'none'">
Box 1&nbsp;
<input type="checkbox" name="hcm2" id="hcm2"
onclick="document.getElementById('demo2').style.display=(this.checked)?'none':'inline'">
Box 2&nbsp;
<input type="checkbox" name="hcm3" id="hcm3"
onclick="document.getElementById('demo3').style.display=(this.checked)?'none':'inline';

document.getElementById('demo4').style.display=(this.checked)?'inline':'none'">
Box 3<br>&nbsp;<br>
<span id="demo1" style="display:none">&nbsp;&nbsp;&nbsp;Box 1 is
checked</span>
<span id="demo2" style="display:inline">&nbsp;&nbsp;&nbsp;Box 2 is not
checked</span>
<span id="demo3" style="display:inline">&nbsp;&nbsp;&nbsp;Box 3 is not
checked</span>
<span id="demo4" style="display:none">&nbsp;&nbsp;&nbsp;Checked Box 3?
Yes</span></p>
+++


A simple exercise is to make a binary adder. Several check boxes represent
binary digits and you want to display the decimal, octal and hexadecimal
values And forget about using any library. That is cheating! (and you
don't learn anything!)

K.

From: Geoff on
On Tue, 23 Mar 2010 22:20:05 -0400, Dr_Kral(a)nyc.rr.com.invalid wrote:

>On Wed, 24 Mar 2010 00:51:01 +0000, Geoff <geoff(a)invalid.invalid> wrote in
><tcoiq59doulsdmrtis7t1uk2joc8baigp7(a)4ax.com>:
>
>>Seem OK/better?!
>Yes it does and much better.
>
>Since JS use zero reference in numbering things, it usually better to do
>the same since then natural loop (j=0;j<xx.length;j++) works well with the
>id parameter as in document.getElementById('demo'+j)
>
>You might try change the style of .visibleDiv to 'inline' rather than
>'block'.
>
>
>Since the conditions to be tested are only ONE check box at a time then one
>can really have simpler code. For example:
>++++
><p>Click the boxes<br>&nbsp;<br>
><input type="checkbox" name="hcm0" id="hcm0"> Box 0&nbsp;
><input type="checkbox" name="hcm1" id="hcm1"
>onclick="document.getElementById('demo1').style.display=(this.checked)?'inline':'none'">
>Box 1&nbsp;
><input type="checkbox" name="hcm2" id="hcm2"
>onclick="document.getElementById('demo2').style.display=(this.checked)?'none':'inline'">
>Box 2&nbsp;
><input type="checkbox" name="hcm3" id="hcm3"
>onclick="document.getElementById('demo3').style.display=(this.checked)?'none':'inline';
>
>document.getElementById('demo4').style.display=(this.checked)?'inline':'none'">
>Box 3<br>&nbsp;<br>
><span id="demo1" style="display:none">&nbsp;&nbsp;&nbsp;Box 1 is
>checked</span>
><span id="demo2" style="display:inline">&nbsp;&nbsp;&nbsp;Box 2 is not
>checked</span>
><span id="demo3" style="display:inline">&nbsp;&nbsp;&nbsp;Box 3 is not
>checked</span>
><span id="demo4" style="display:none">&nbsp;&nbsp;&nbsp;Checked Box 3?
>Yes</span></p>
>+++

K.

I seem to be OK now using your approach above?

http://www.micro-active.com/a-wm2/a-q-student-wm2.htm

Cheers

Geoff




>
>A simple exercise is to make a binary adder. Several check boxes represent
>binary digits and you want to display the decimal, octal and hexadecimal
>values And forget about using any library. That is cheating! (and you
>don't learn anything!)
>
>K.
From: Dr_Kral on
On Wed, 24 Mar 2010 10:50:34 +0000, Geoff <geoff(a)invalid.invalid> wrote in
<iirjq5hho7dlnagemttfl8q8ma5dqvpmd0(a)4ax.com>:


>I seem to be OK now using your approach above?
>
>http://www.micro-active.com/a-wm2/a-q-student-wm2.htm
>
Yes, things are a lot better now although there are a lot of changes that I
would make due to my preferences. But that does not make your way wrong.

There are some things that you apparently don't understand from the way
that you implemented the changes.

First, there is no any point in interrogating the state of a radio button
with onclick like there is for a check box. The former is always 'true'
while the latter may be either true or falue.

Second, in my example I used ...this..... which you changed to
.....id_name.... "this" is a special reserved word but the id_name should
be "document.getElementById(id_name)" to properly identify the object.

Third, you made but the true and false results of the conditional operator
the same in, e.g., question 13, which is not a reasonable thing to do.

K
From: Geoff on
On Thu, 25 Mar 2010 19:18:29 -0400, Dr_Kral(a)nyc.rr.com.invalid wrote:

>First, there is no any point in interrogating the state of a radio button
>with onclick like there is for a check box. The former is always 'true'
>while the latter may be either true or falue.

K.

Is this correct?

onclick="document.getElementById('id_13a').style.display='inline'" for
yes

and

onclick="document.getElementById('id_13a').style.display='none'" for
no

>Second, in my example I used ...this..... which you changed to
>....id_name.... "this" is a special reserved word but the id_name should
>be "document.getElementById(id_name)" to properly identify the object.

I have now used 'this.checked' etc for the checkboxes.

>Third, you made but the true and false results of the conditional operator
>the same in, e.g., question 13, which is not a reasonable thing to do.

I didn't like that but couldn't see how else to do it. I have now
removed the ternary condition for the radio buttons.

http://www.micro-active.com/a-wm2/a-q-student-wm2.htm

Cheers

Geoff