Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JavaScript-created checkbox not initialized on page refresh

52 views
Skip to first unread message

Chris Beall

unread,
Jan 16, 2012, 9:43:11 PM1/16/12
to
Every now and then I come across some simple problem that leads me to
believe I have missed some fundamental understanding of How Things Work.
This is such a case.

URL: http://stl.beallsprings.org/conservation%20easement.html

(Yes, there are unencoded ampersands on the page and a few missing alt=
attributes. I'll be fixing those while you contemplate the actual
question.)

In the upper right corner of the page is a checkbox, created via
JavaScript in the body of the HTML thus:
document.write('<input type="checkbox" id="notecheck" checked
onclick="filter()">Show annotations');

Note the 'checked' entry, which causes the box to be checked when it is
created. Consistent with that check, the annotations on the page (in a
sans-serif font) are visible.

Now UNcheck the box. The annotations go away (and the background color
changes to a sort of yellow as a reminder that you are looking at the
original document, verbatim.) All is well.

Now refresh the page. Bummer. The page, as expected, again contains the
annotations (and the white background), but the checkbox is still
unchecked, so the two are now out of sync.

When I refresh a page, shouldn't the JavaScript be executed again? And,
if so, shouldn't the 'checked' entry cause the box to again be initialized
in the checked state?

An explanation would be appreciated, but even better would be a pointer to
a technical spec where this is discussed.

I have developed a workaround, which is to explicitly check the box within
a body onload=function which does seem to get executed on a page refresh.
An example, on a rather more complex page with several checkboxes, is at
http://stl.beallsprings.org/Timeline.html


Chris Beall

Chris Beall

unread,
Jan 16, 2012, 10:58:05 PM1/16/12
to
On Mon, 16 Jan 2012 21:43:11 -0500, Chris Beall <Chris...@prodigy.net>
wrote:

(snip)

> URL: http://stl.beallsprings.org/conservation%20easement.html
(snip)

> Now UNcheck the box. The annotations go away (and the background color
> changes to a sort of yellow as a reminder that you are looking at the
> original document, verbatim.) All is well.
>
> Now refresh the page. Bummer. The page, as expected, again contains
> the annotations (and the white background), but the checkbox is still
> unchecked, so the two are now out of sync.
(snip)

Hmmm. More extensive testing shows that this issue seems to be confined to
Firefox. The checkbox is re-checked on a page refresh on Chrome, Safari,
and Opera.

I'd still be interested to know where something like this authoritatively
documented, if such a place exists...

> Chris Beall

Chris Beall

unread,
Jan 17, 2012, 3:07:16 PM1/17/12
to
On Mon, 16 Jan 2012 22:58:05 -0500, Chris Beall <Chris...@prodigy.net>
wrote:

> On Mon, 16 Jan 2012 21:43:11 -0500, Chris Beall
> <Chris...@prodigy.net> wrote:
>
> (snip)
>
>> URL: http://stl.beallsprings.org/conservation%20easement.html
> (snip)
>
>> Now UNcheck the box. The annotations go away (and the background color
>> changes to a sort of yellow as a reminder that you are looking at the
>> original document, verbatim.) All is well.
>>
>> Now refresh the page. Bummer. The page, as expected, again contains
>> the annotations (and the white background), but the checkbox is still
>> unchecked, so the two are now out of sync.
> (snip)
>
> Hmmm. More extensive testing shows that this issue seems to be confined
> to Firefox. The checkbox is re-checked on a page refresh on Chrome,
> Safari, and Opera.

This seems to result from a philosophy described in Bugzilla bug #654072
(https://bugzilla.mozilla.org/show_bug.cgi?id=654072), to which I have
added this instance as an example of why the philosophy is, perhaps,
flawed.

>> Chris Beall

Dr J R Stockton

unread,
Jan 18, 2012, 12:21:12 PM1/18/12
to
In comp.infosystems.www.authoring.site-design message
<op.v78vi...@chris-bealls-imac.local>, Tue, 17 Jan 2012 15:07:16,
Chris Beall <Chris...@prodigy.net> posted:
In testing, I find it useful; and, when I want it not to happen, I use
another browser.

You may well be able to get what you want by using <body onload="...">
to act as if the checkbox has just been clicked, or to clear the
checkbox by code.

--
(c) John Stockton, nr London UK ?@merlyn.demon.co.uk IE8 FF8 Op11 Sf5 Cr15
news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
<http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Chris Beall

unread,
Jan 18, 2012, 7:59:26 PM1/18/12
to
Yes, that's exactly what I've done, on another page, as a workaround.
More details in the bug report cited above. I'm leaving the original
intact for now as an example of the problem.
0 new messages