Connecting Tech Pros Worldwide Help | Site Map

FAQ update (roundup of pending requests - for comment)

Richard Cornford
Guest
 
Posts: n/a
#1: Jul 20 '05
You may have noticed Jim saying that he is too busy to do an
update of the FAQ at the moment and asking for volunteers to
edit the next (and possibly future) revision. He had already
asked me if I was interested and I did volunteer, pointing out
that because I am a dyslexic with a tendency to be long-winded[1]
I might not be the best candidate for the job of FAQ editor.
However, Jim asked me to do it, which probably means that
nobody else volunteered at all.

I have successfully established access to Jim's server and am
ready to start the next revision of the FAQ. To that end I have
searched the c.l.j. archives for <FAQ**TRY> (modified here and
below so that this post and quoting responses do not show up in
future searches) and below is a roundup of requests made since
the last update and my initial thoughts on them.

I would appreciate any feedback, comments, suggestions, additions,
alternatives, etc. that anyone feels like contributing prior to
making any changes to the existing FAQ:-

<URL: http://jibbering.com/faq/ >

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

<quote
cite="http://groups.google.com/groups?selm=xLUAe3Ccsy5%24Ewqq%40merlyn.d
emon.co.uk"
author="Dr John Stockton"
subject="Use of javascript/Jscript at Win32 DOS prompt">

I believe that an entry in Section 4 of the FAQ would be
worthwhile; just illustrating starting javascript-in-WSH
from the command line and from, say, File Manager & Internet
Explorer, and giving a well-chosen link or two.

It could include
<script type="text/javascript" src="include1.js"></script>
&
<script type="text/javascript">
...
</script><noscript> ... </noscript>
- they may be strictly HTML, but they are important to
Web use of javascript, and often given wrongly in the group.

Perhaps a possible <FAQ**TRY> could be composed here, if
Jim would like to use such.


The FAQ has not been updated lately, and new expertise has
come into the group. Might it be worth jointly reviewing
one numbered part here each week, starting I suggest at 3.1
and working round to 2.12 then 3.1 again?

Re 3.1 - I find the Pocket Reference Flanagan very useful;
it is cheaper & smaller.

Re 3.2 - Nothing to say about the intent, but I'd prefer <p>
instead of <BR> before each subsubsection.

</quote>

I see an number of FAQ addition/modification requests here:-

1. The addition of a question on using/executing WSH/JScript
for .BAT style (Windows) OS automation.

I will not be writing that entry as I have little experience
of doing that so, though I am not opposed to the idea in general,
I would need a more concrete proposal to start from. But I would
also need to see some wider support for its inclusion, as it is
not really a FAQ (just something that JavaScript authors might be
inclined to employ/exploit).

2. Something on writing formal ((x)HTML DTD valid) script tags.

If that is the correct interpretation, it has been suggested a few
times an I will return to it below.

3. Instigating a process of rolling review/modification of the FAQ
section by section.

Having just gone through the FAQ requests for the last 7 months I
think small regular updates might actually be easier but I am
reluctant to commit myself to a rolling process, at least without
evidence of general support for (and a willingness to contribute
to) the process on the part a reasonable number of regulars in the
group. (So if anyone else likes this idea, now it the time to say
so).

4. The inclusion of:-
JavaScript Pocket Reference, by David Flanagan, pub. O'Reilly
& Associates Inc. (Sebastopol, CA, US) 1998, ISBN 1-56592-521-1,
89 pages, £5.50.
-in the book recommendations in section 3.1.

I have never read (or to the best of my knowledge, set eyes upon)
that book so I could not, in good conscience, make the decision
one way or the other. But there are a lot of JavaScript books
that I have not read so I will have to adopt a policy of not
including book recommendations without widespread support (3 or
more endorsements) for the books in questions (from people who's
opinions I trust).

If anyone is in a position to express their opinion on the
suitability of "JavaScript Pocket Reference" by David Flanagan
for inclusion in the FAQ please do so. And, as usual, suggestion
for other books that would be suitable for recommendation in the
FAQ are also welcome (though authors of JavaScript books should
probably consider the generally negative attitude within this
group toward most existing JavaScript books, and therefor the
possibility of generating negative publicity that might result
form proposing volumes that may be considered unsuitable for
inclusion in the FAQ).

5. Altering the HTML version of the FAQ so that Section 3.2 is marked
up differently.

You propose P elements here and UL/LI in a later FAQENTRY request.
I would agree that that section of the FAQ comes out a bit
bunched up and could benefit from different mark-up but the HTML
version of the FAQ is generated from the same XML file as the
text versions that are posted to the group so changing the
mark-up would involve re-writing (at least parts of) the script
that generates the HTML from the XML. It looks like the change
would be feasible but I was not planning to re-write Jim's
scripts.

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

<quote
cite="http://groups.google.com/groups?selm=9mfTlhNzVsJ%24EwpW%40merlyn.d
emon.co.uk"
author="Dr John Stockton"
subject="Stylistic concerns for large application">

If you had looked in the regularly -posted and -cited FAQ, you
would have found no relevant occurrence of "include", which
seems a pity.

Most of my javascript date pages use include files; but start at
<URL:http://www.merlyn.demon.co.uk/js-index.htm#IF>, visit
<URL:http://www.merlyn.demon.co.uk/js-nclds.htm> and
<URL:http://www.merlyn.demon.co.uk/js-other.htm>.

<FAQ**TRY> - something on include files?

And perhaps the FAQ could link to an associated demonstration
page, intended to be most illustrative under View Source??

Might FAQ 3.2 be more readable with <ul> ... <li> ... </ul> ?

</FAQ**TRY>

</quote>

By "include files" I assume you mean JS files referenced with the
SRC attribute of script elements. I suppose that should mention
what should be in those JS files (or rather what should be omitted,
i.e. any HTML mark-up including script tags and HTML comments). How
the SRC attribute would be written in a script tag (possibly that
would be covered in an entry on the language attribute verses
type="text/javascript") and go on to describe the possibility of
document.write-ing (possibly dynamically constructed) script tags
and maybe some alternatives such as createElement("script") etc.

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

<quote
cite="http://groups.google.com/groups?selm=C1hsBCBJic5%24EwO5%40merlyn.d
emon.co.uk"
author="Dr John Stockton"
subject="parseInt .5">

I think you need to spend considerably more time reading and
testing, and less time writing.

That function returns 50 for inputs of +5 & -5; and 00 for 0.

function LZ(x) {return(x<0||x>9?"":"0")+x} // for integers

is reliable, and has the possible advantage of always returning
a string.

There is no leading zero function in the FAQ <FAQ**TRY> bur
perhaps there should be; one so often sees repetitive coding
for it.

<URL:http://www.merlyn.demon.co.uk/js-maths.htm#LZ> refers.
</quote>

I wonder if that could/should be slipped in at the end of 4.6 as
that already discusses the generation of formatted number strings.
Perhaps changing the question so that it is about less specific
number formatting.

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

<quote
cite="http://groups.google.com/groups?selm=pldmFJG%247t4%24Ewzt%40merlyn
..demon.co.uk"
author="Dr John Stockton"
subject="javascript to create dynamic HTML? (Google AdSense)">
[color=blue]
>Hmmm, well, I'm not that fanatic, but... have you found any
>way to make mozilla use doublebuffering or to just paint over
>the old canvas instead of first clearing it? With the current
>implementation the date is flickering.[/color]

No. One reason is that I do not have, and probably have never
seen, at least since 1996, Mozilla.

But if Mozilla does flicker in some or all sorts of rewrite, that
could deserve a "how do I prevent it" <FAQ**TRY>, even if the
answer is that it is not preventable.

IIRC, can one arrange, as for the Dynamic Graphic above the
first button in <URL:http://www.merlyn.demon.co.uk/js-date3.htm>,
that only the changed digits are rewritten? The date might then
only flicker at midnight.

</quote>

I don't recall noticing any significant flickering problem with
Mozilla/Gecko browsers and I don't see any flickering on
js-date3.htm in or around the Dynamic Graphic while it is running.

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

<quote
cite="http://groups.google.com/groups?selm=3FDBC2B2.1020908%40PointedEar
s.de"
author="Thomas 'PointedEars' Lahn"
subject="window.opener.location.reload();">

Q: My script does not work. How do I make it work?

A: "Does not work" is a useless error description. [psf 4.11]
[color=blue]
> Suggestions?[/color]

If JavaScript support is present and enabled, debug the script.


Internet Explorer
------------------

Select Internet Settings, Extras(?; last tab), then

[X] Show script errors

To use a debugger:
[_] Disable script debugging

The Microsoft Script Debugger can be downloaded from
http://www.microsoft.com/downloads/d...606E71F-BA7F-4
71E-A57D-F2216D81EC3D&displaylang=en

The How-To can be found at
http://msdn.microsoft.com/library/de.../en-us/sdbug/H
tml/sdbug_1.asp

A script debugger is also included in Microsoft Visual Studio.


Netscape 3.x+ and
Mozilla/5.0 (incl. Netscape 6+, Mozilla Firebird, ...)
-------------------------------------------------------

Type `javascript:' in the Location Bar to show the JavaScript
Console.


Mozilla/5.0
------------

In Mozilla, select Tools (menu), Web Development, JavaScript
Console. In Netscape 6+, select Extras(?), Tasks(?), JavaScript
Console.

Select Tools, Web Development, JavaScript Debugger. If
Venkman, the JavaScript Debugger for Mozilla/5.0 is not yet
installed, either update your Mozilla/5.0 and select `Debugger'
in the Custom Setup, or download and install Venkman as Cross
Platform Installation (XPI) from

<http://www.hacksrus.com/~ginda/venkman/>

How-Tos can be found there, too.


Opera
------

Select File, Preferences, Multimedia, then

[X] Enable JavaScript
[X] Open JavaScript console on error


$Foobar
--------

RTFM.

</quote>

The first point: "Does not work" is a useless error description.
Is a valid point and "does not work", as a bug report has
deservedly been subject to a lot of criticism recently. I don't
think that it should be addressed in the quick answers section
but maybe 2.3 could be modified to stress the point.

Possibly re-wording the second paragraph of section 2.3 to read:-

<draft>
Please state your question as clearly and concisely as possible,
as this will make it far easier for the other readers of the list
to understand your problems and suggest possible solutions. Try
to explain: 1. What you have done. 2. What you expected to
happen. 3. What really happened. Use the Subject: of your post
to indicate the type of problem you have, but include the
question in the body as well. 'Help!' or 'I hate Netscape!'
are not nearly as useful to contributors who do not read every
post as 'parseInt("09")!=9'.
</draft>

The second suggestion strikes me as proposing an entry in section
4 that explains how to enable error reporting on at least the
major browsers. Possibly with references to debuggers (though
venkman is already referenced in section 3.2).

As usual that is not often specifically asked as a question but
the information is frequently posted in replies so it probably
does deserve consideration for a place in section 4.

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

<quote
cite="http://groups.google.com/groups?selm=mCpVM0BLLLx%24EwZL%40merlyn.d
emon.co.uk"
author="Dr John Stockton"
subject="Need help in validating the period in an email address (new
JavaScript student)">

<FAQ**TRY> The FAQ should also say that, when asking about
classwork, a poster needs to state that it is classwork
(and to present what he/she has done so far, which you did).
</FAQ**TRY>

</quote>

That would be changes to section 2.3 again, but people asking
about classwork is not that common (except just before the end of
academic years/terms).

I don't want to include this as it addresses a small minority.

It might be worth suggesting that people explain the context in
which they are asking their questions in the hope that they would
mention when it was for an educational course but my experience
suggests that often students are looking to have there homework
done for them and know that admitting that it is homework would
not produce their desired result.

Personally I like the approach to posts from students who are
attempting to pass their homework of as a real web project that
I first observed employed by Yep: posting a complete solution
using such advanced techniques (closures, OO and full
cross-browser support/fall-back) that no student who could not
solve the original problem could hope to pass it off as their
own work.

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

<quote
cite="http://groups.google.com/groups?selm=gqMUWlHBpCm%24Ewy4%40merlyn.d
emon.co.uk"
author="Dr John Stockton"
subject="Javascript Daylight time problem...">
[color=blue]
>You use Date in several places. *Not* handling daylight
>saving is a very date specific act two times a year.[/color]

More often than that. Outside the EU, many countries (some
quite respectable) change on different dates; some, such as
Australia and New Zealand, have good reason for doing so.
I think the EU change dates, surely the EU change-instants,
are more commonly used than any others.

But at most twice per calendar year in any given location.

<FAQ**TRY> The FAQ is rather terse with its date advice; it
might help if it had an explicit date-time question, and the
one implicit in this thread might be good to choose.

</quote>

I can see some value in having a question that specifically
relates to the use of the Date object, mostly to server as a
way of channelling people interested in the Date object to more
detailed information on the subject. Daylight saving might be a
bit specialised (and maybe require too much code/explanation).

I suppose what we need is to find an expert of the Date object to
come up with a *short* general question and answer on the Date
object and some resources to reference for more details ;-)

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

<quote
cite="http://groups.google.com/groups?selm=20031019174853.28496.00001388
%40mb-m18.aol.com"
author="HikksNotAtHome"
subject="Client-side Javascript validation of "select multiple" for PHP
">

http://www.jibbering.com/faq/#FAQ4_25
Incorrectly states that [] are illegal characters in HTML.
It was discussed not long ago and I believe the final concensus
was that [] are in fact legal in the name.

</quote>

This one is very important as the FAQ should not be demonstrably
incorrect. Currently it reads:-

4.25 My element is named myselect[] , how do I access it?

Form elements with any "illegal" characters can be accessed
with formref.elements["myselect[]"] - These characters are
illegal in the standard (x)HTML doctypes, so you should try
to avoid them as browsers may perform incorrectly though.

The first "illegal" could stay as it could be argued that the
characters are illegal in some contexts (JavaScript identifiers)
but the second sentence must be re-worded. Maybe:-

<draft>
"These characters are illegal within ID attributes in the
standard (x)HTML doctypes and javascript Identifiers, so you
should try to avoid them as browsers may handle them
incorrectly."
</draft>

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

<quote
cite="http://groups.google.com/groups?selm=9mTTlqNfXse%24EwRV%40merlyn.d
emon.co.uk"
author="Dr John Stockton"
subject="How to use window.open() ?">

By composing text within a right margin of about 72 characters,
in accordance with standard Usenet recommendation, you can make
your material more readily readable to those with standard
72-column eyes or 80-column display windows.

<FAQ**TRY> Jim, I don't see a mention of posting margin or
line-wrap in 2.3 </FAQ**TRY>.

</quote>

<quote
cite="http://groups.google.com/groups?selm=s7NHCxBRAST%24Ew6S%40merly.d
emon.co.uk"
author="Dr John Stockton"
subject="Need special kind of countdown timer ">

Please set your right margin at about 72 characters. It is
easier to read, and quotes better in standards-compliant
newsreaders. See references in FAQ. <FAQ**TRY> Mention margin
in 2.3? </FAQ**TRY>

</quote>

Jim seems to be resistant to mentioning margins in section 2.3
and I am also inclined to leave that out. As it is there is a
constant struggle to get people to follow the existing posting
guidelines in section 2.3. The people who will not respect the
existing guidelines are not going to be influenced by a specified
margin and the people who do follow them don't seem to take much
persuading to use a suitable margin.

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

<quote
cite="http://groups.google.com/groups?selm=fK6b%2BsBp0j6%2BEwiN%40merlyn
..demon.co.uk"
author="Dr John Stockton"
subject="Force user to open in IE">
[color=blue]
>I'd like to know if there is a way to force a user to open
>a link on my page in I.E. even if they are using Netscape.?[/color]

Not even Bill Gates can do that directly.

Vcards are merely a source of annoyance for many readers.
<FAQ**TRY>?

</quote>

Of all the possible sources of annoyance? I am not inclined to
include this.

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

<quote
cite="http://groups.google.com/groups?selm=ptk4xjcl.fsf%40hotpop.com"
author="Lasse Reichstein Nielsen"
subject="dependable select boxes">

<FAQ**TRY>
You can add options to a select element using "selectRef.add"
and remove them with "selectRef.remove", although these
functions are not present in older browsers.

You need to keep the new data somewhere else, probably as an
array of text/value pairs.

The following function changes the options of a select element:
---
function setOptions(selectRef,optArray) {
var optsRef = selectRef.options;
// Clear old options
optsRef.length = 0;
// Insert new options
for (var i = 0 ; i < optArray.length-1 ; i += 2) {
var opt = new Option(optArray[i],optArray[i+1]); // text,value
optsRef[optsRef.length] = opt;
}
}
---
You can use this function from the onchange handler of another
select element.
</FAQ**TRY>

</quote>

Successfully handling the manipulation of option elements in a select
element is one of those things that probably deserves considerably
more information than would fit well in a quick answer. There are
always the design and fall-back/clean degradation issues in addition
to the pure mechanics of creating and appending new Option elements.

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

<quote
cite="http://groups.google.com/groups?selm=TC%24YsJEdhqC%24EwXo%40merlyn
..demon.co.uk"
author="Dr John Stockton"
subject="Question ">
[color=blue]
>What I'm trying to do is have the web page placed on a web
>server and have the list automatically update every time a
>file is uploaded. Is there a way to do that?? The list will
>be on the web page.[/color]

That requires server-side coding.

That's fully on-topic AIUI; OTOH the _default_ assumption here
is that code is for execution in an Internet Web browser.
See FAQ 2.2 para 1.

<FAQNONENTRY> - Jim, I can't see the new FAQ on the Web. ???

<FAQ**TRY> At the end of that para, "... which host ..." - in
the default case, where the javascript is used in a Web browser,
a major point is that the author does not really know which host
will be used. Could it be rephrased? "... which type of host ..."
seems better but may not be best.

</quote>

Presumably "type of host" refers to web browsers, servers,
WSH and others, while "host" alone might imply a single
browser. I will change that, though I would be open to other
alternative wordings.

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

<quote
cite="http://groups.google.com/groups?selm=20030827045359.11891.00000254
%40mb-m11.aol.com"
author="HikksNotAtHome"
subject="Scrolling Table - Which browsers support this code ">

http://www.metalusions.com/backstage/articles/8/

if(document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}

<FAQ**TRY>
document.getElementById for IE4?
</FAQ**TRY>

Thoughts and comments?
Specifically, are there any cases where the above fails in IE4?
Or, any other browsers that will pass the test other than IE4?
I recall Jim mentioning one that supported document.all and
document.layers at the same time.

</quote>

<quote
cite="http://groups.google.com/groups?selm=20030624173732.17796.00001037
%40mb-m15.aol.com"
author="HikksNotAtHome"
subject="Script Won't Upload in Netscape">

<FAQ**TRY>
http://www.metalusions.com/backstage/articles/8/
</FAQ**TRY>

I posted that URL a while back, don't remember if I offered it
as an FAQEntry or not though.

if(document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}

</quote>

<quote
cite="http://groups.google.com/groups?selm=9bbDq4IpDw7%24Ew6Q%40merlyn.d
emon.co.uk"
author="Dr John Stockton"
subject="prototyping document.getElementById">
[color=blue]
>I'm thinking of prototyping document.getElementById for those
>browsers that understand document.all but not
>document.getElementById (IE4).
>
>Is that a reasonable thing to do? Suggestions?[/color]


Article
From: hikksnotathome@aol.com (HikksNotAtHome)
Newsgroups: comp.lang.javascript
Date: 24 Jun 2003 21:37:32 GMT
Subject: Re: Script Won't Upload in Netscape
Message-ID: <20030624173732.17796.00001037@mb-m15.aol.com>

included

if (document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}

That looks worth a <FAQ**TRY> to me; and I put it in my
<URL:http://www.merlyn.demon.co.uk/js-other.htm>
as an example of Object Detection.

</quote>

I wonder whether including this is a good idea. I would handle
IDed element retrieval with a specific function that either
handled the fall-back from getElementById itself or had been
set up during configuration to handle the fall-back. I generally
don't like attempts to "normalise" browsers to a homogenised DOM.

Opinions?

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

<quote
cite="http://groups.google.com/groups?selm=he0col2r.fsf%40hotpop.com"
author="Lasse Reichstein Nielsen"
subject="Javascript in netscape navigator">

<FAQ**TRY>
Why doesn't the global variable "divId" refer to the
element with id="divId"?

It does in Internet Explorer, but not in *many* other browsers.
The recommended way of referring to an element with id="foo" is
document.getElementById("foo")
In order to support older browsers that doesn't implement this
W3C DOM method, fallback to proprietary features can be used. In
Internet Explorer 4 (and WebTV?), you can use document.all["foo"] .
In Netscape 4, maybe you can use document.layers["foo"] ,
but only if the element is absolutely positioned (or created with
the Netscape 4 proprietary <layer> tag).


<URL:http://www.mozilla.org/docs/web-deve...tml#dom_access[color=blue]
>[/color]
</FAQ**TRY>

</quote>

In one form or another this proposal is going into the FAQ. I
originally proposed a longer alternative to Lasse's but Jim
favoured making it considerably shorter and omitting all the
references to fall-back.

My current version is:-

<draft>
4.41 Why doesn't the global variable "divId" always refer to
the element with id="divId"?

A common shortcut(introduced by IE and reproduced in some
other browsers) in accessing DOM elements that have ID
attributes is to use a provided global variable with the same
name as the element's ID string. However, the best approach is
the document.getElementById method, which is part of the W3C
DOM standard and implemented in modern browsers (including
IE from version 5.0). So an element with id="foo" can be
referenced with:-

var el = document.getElementById("foo");


<URL:http://www.mozilla.org/docs/web-deve...tml#dom_access[color=blue]
>[/color]
</draft>

As usual, comments, criticisms, corrections and alternatives are
welcome.

Having decided to remove Lasse's consideration of fall-back from this
entry it might be worth re-considering Randy's IE 4 fall back for
getElementById.

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

<quote
cite="http://groups.google.com/groups?selm=D25cBcE%2B0u8%2BEwC7%40merlyn
..demon.co.uk"
author="Dr John Stockton"
subject="Downloadnig HTML source code">
[color=blue]
>File>Save As will give it to you, very easily, in MSIE's
>warped way of rendering but it adds some extra code to it
>and messes up the original folder organization. Netscape 7
>seems to save it as it is sent by the server though.[/color]


Given the degree of variation in what people say happens (and
that in what can happen), and the frequency with which viewing
the source of a Web page is recommended in this group, ISTM
that a <FAQ**TRY> on viewing source could be justified, perhaps
adjacent to that on hiding source.

Perhaps a short paragraph outlining the possibilities, and if
available a link to elsewhere.



FAQ 4.38 is rather brief, from the point of view of an off-line reader;
could LB produce a sentence describing the basis?

</quote>

I am unsure what an entry on viewing source would say.
Server-scripters often don't seem to appreciate that debugging
client-side JavaScript is better done using the source the
browser receives instead of the server-script that generates
it, but do that many people need to be told how to view the source?

4.38 will have to stay as it is unless Laurent (or someone else)
comes up with an additional sentence (probably literally). And I
suspect that the subject could not be usefully addressed in just
one sentence, or any statement that was sufficiently short.

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

<quote
cite="http://groups.google.com/groups?selm=Lc%24%2BrFC8alK%24EwFy%40merl
yn.demon.co.uk"
author="Dr John Stockton"
subject="Script tag - language version">
[color=blue]
>Use the type attribute instead:
>
><script type="text/javascript">[/color]

<FAQ**TRY> That (slightly expanded) is now a FAQ candidate,
IMHO.

</quote>

<quote
cite="http://groups.google.com/groups?selm=20031008225410.21542.00000503
%40mb-m02.aol.com"
author="HikksNotAtHome"
subject="Two Questions about the Following Block of Code">
[color=blue]
><script language="JavaScript">[/color]
Language attribute is deprecated in favor of the type
attribute: text="type/javascript"

<FAQ**TRY>
type="text/javascript" in favor of language="javascript"
</FAQ**TRY>

Not sure on a wording, but its seen a lot here :-(

</quote>

This certainly is frequently mentioned so it might deserve an entry.

So would the section 4 question be "How do I write HTML 4 valid
script tags?" or "How do I write script tags?"? With the latter
having to go into more detail on the LANGUAGE attribute (and
possibly language version numbers and their associated problems).

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

<quote
cite="http://groups.google.com/groups?selm=opJmGAJLIix%2BEwvg%40merlyn.d
emon.co.uk"
author="Dr John Stockton"
subject="Money Format Problem">

Revised <FAQ**TRY> 4.6

4.6 How to convert a Number into a String with exactly 2
decimal places?

For example, to format 6.57634 to 6.58, 6.5 to 6.50,
and 6 to 6.00?

Rounding of x.xx5 is uncertain, as such numbers are not
represented exactly.

N = Math.round(N*100)/100 only converts N to a Number of
value close to a multiple of 0.01; but document.write(N)
does not give trailing zeroes.

ECMAScript Ed. 3.0 (JScript 5.5 (but buggy) and JavaScript 1.5)
introduced N.toFixed, but that <test & describe what it does> .

Much code for trailing zeros fails for some numbers
(e.g. 0.07). The following works successfully :

BOX
BOX

Method toFixed in the box above is intended to do what
browser toFixed ought to do, not to be equivalent.


// Note that code I now use, at
<URL:http://www.merlyn.demon.co.uk/js-round.htm#GC>,
differs a little from what is in the FAQ.

</quote>

The first request is to describe and test what toFixed actually
does rather than just asserting that it is buggey in its
implementations (4th paragraph). That sounds like it could be
quite a large addition.

Adding a final note saying that the assigned
Number.prototype.toFixed function is not equivalent to the
original doesn't strike me as necessary.

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

<quote
cite="http://groups.google.com/groups?selm=iRmk4bYyUOw%2BEwki%40merlyn.d
emon.co.uk"
author="Dr John Stockton"
subject="New to java">
[color=blue]
>You do not need any javascript to do this. Just standard
>HTML with a bit of CSS to control the background image on
>mouseover.[/color]

There being questions which can quite reasonably be considered,
/a priori/, to be javascript questions, but for which answers
such as the above are appropriate, ISTM that it would be well
<FAQ**TRY> for the FAQ to include, described as such, one or
two links to well-written introductory CSS information.

</quote>

Perhaps an opportunity to assert the general principal that if
something can be done without JavaScript then it should be done
without JavaScript. I don't see an easy way of making that
point, for example, suppose the question was "What is the best
strategy for using JavaScript on the Internet?". That might
certainly mention the preceding principal (and reference CSS as
a result) along with such things as treating JavaScript as a
means of providing optional enhancements and clean degradation.
Then again it might just result in an extended argument about
what the "best strategy" is.

Anyone care to start the ball rolling?

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

<quote
cite="http://groups.google.com/groups?selm=20030608204652.04207.00000619
%40mb-m01.aol.com"
author="HikksNotAtHome"
subject="FAQ Updates">

Any chance of an added entry on the problems, and possible
solutions, to popup windows? Or even just links to articles
on the problems with using it?

Whats wrong with window.open(...)?

</quote>

At the time I though that this suggestion deserved more
consideration. The opening of windows with JavaScript
certainly is frequently the subject of questions on the
group and is frequently unwisely handled by script authors.

To start with we would need some resources to reference on
the subject, and preferably not pages that gloss-over the
problems of opening window. For that purpose
Lasse Reichstein Nielsen's page:-

<URL: http://www.infimum.dk/HTML/JSwindows.html >

-is probably the best candidate that I have seen. While it is
not as negative about the idea of opening new windows as I
would be, it does not conceal the potential problems and even
directly states that window opening is widely considered
unsuitable for anything important. It would be nice to be able
to also add a page on achieving pop-up like effects without
using new browser instances (or modal dialogs).

The question it self could be fairly simple:-
<draft>
4.nn How do I open a new window with JavaScript?

New windows can be opened on browsers that support the
window.open function and are not subject to the action
of any pop-up blocking mechanism with code such as:-

if(window.open){
wRef = window.open("http://example.com/page.html", "windowName");
}

<URL; resource references>
</draft>

But there is a great deal omitted from the above, including any
consideration of the window features list.

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

<quote
cite="http://groups.google.com/groups?selm=v0%243h1FuCs%2B%24Ewzm%40merl
yn.demon.co.uk"
author="Dr John Stockton"
subject="Environment Variables in WSH JS">

Aside : <FAQ**TRY> 2.11 : "over 5 years" is IMHO ambiguous.
Suggest "more than 5 years" or "for 5 years", whichever is meant.

</quote>

Yes, I will change that to "more than 5 years".

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

The code used in section 4.15 has come in for a lot of comment lately.
While it is not the code I would use for the task, the existing code
is short, will work successfully in browsers that support innerHTML
and the text includes the pertinent caveats. So I am inclined to
leave it as it is for the time being, unless a strong feeling that
it should be changed (baring in mind the need for brevity) is
expressed.

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

Richard.

[1] The only practical consequence is that I will not be
offended if anyone feels like criticising/correcting my spelling
and/or grammar. And I also won't object to suggestions of more
concise wordings where available.


Dr John Stockton
Guest
 
Posts: n/a
#2: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <btfs7p$5gs$1$8300dec7@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Richard@litotes.demon.co.uk> posted at Wed, 7 Jan 2004 02:51:35 :-

[color=blue]
>1. The addition of a question on using/executing WSH/JScript
> for .BAT style (Windows) OS automation.
>
> I will not be writing that entry as I have little experience
> of doing that so, though I am not opposed to the idea in general,
> I would need a more concrete proposal to start from. But I would
> also need to see some wider support for its inclusion, as it is
> not really a FAQ (just something that JavaScript authors might be
> inclined to employ/exploit).[/color]

One reason for suggesting it is that I would like to have read such an
entry, preferably a few years ago. However, the major point seems to be
to say, more obviously than at present, that javascript (and VBscript)
can be executed as Win32 programs, and with more capabilities than
allowable in browsers. Most of what I know is at <URL:http://www.merlyn
..demon.co.uk/batfiles.htm#WSH> (new Anchor).

The most important thing is to indicate that the possibility exists,
better than 2.8 does at present.


If restructuring, one could start Sec.2 with a new 2.0 "What is
javascript, and what is it for? - that would then absorb 2.6 & 2.7 &
maybe 2.12 as subsubsections, and a slight enlargement of 2.8 sentence 3
to cover "what for".

"Javascript (and VBscript) can be used (a) in Web pages, which is the
default assumption here; (b) in Intranet pages; (c) in Win32 with
Windows Scripting Host, for general purposes; (d) in Web servers...; (e)
.... ?"





[color=blue]
>By "include files" I assume you mean JS files referenced with the
>SRC attribute of script elements. I suppose that should mention
>what should be in those JS files (or rather what should be omitted,
>i.e. any HTML mark-up including script tags and HTML comments). How
>the SRC attribute would be written in a script tag (possibly that
>would be covered in an entry on the language attribute verses
>type="text/javascript") and go on to describe the possibility of
>document.write-ing (possibly dynamically constructed) script tags
>and maybe some alternatives such as createElement("script") etc.[/color]

Not necessarily as much as that in the FAQ itself. But a scan of the
FAQ for include and for src finds nothing related. Perhaps no more need
be said than the essence of <URL:http://www.merlyn.demon.co.uk/js-
other.htm#Inc>.




[color=blue]
>That function returns 50 for inputs of +5 & -5; and 00 for 0.
>
> function LZ(x) {return(x<0||x>9?"":"0")+x} // for integers[/color]
[color=blue]
>I wonder if that could/should be slipped in at the end of 4.6 as
>that already discusses the generation of formatted number strings.
>Perhaps changing the question so that it is about less specific
>number formatting.[/color]

IMHO, the item needs to be evident in sec. 4 of the index; i.e. in
Subject(4.6).modified or under a new Subject.


[color=blue]
>I suppose what we need is to find an expert of the Date object to
>come up with a *short* general question and answer on the Date
>object and some resources to reference for more details ;-)[/color]

While Summer Time is not often asked about, it is quite often answered
about.

Qn : Why does date ( differencing | incrementing ) go wrong?
Ans : Date is basically held as GMT, so date arithmetic across Summer
Time transitions needs particular care. Examples :

(new Date('2004/11/01') - new Date('2004/10/01'))/864e5 // is 31.0416
new Date(new Date('2004/10/01').getTime()+31*864e5).getDate() // is 31
// Better examples may spontaneously appear.

Note that that the term "Summer Time" usefully introduces the string
"Time" for search-fodder.











[color=blue]
>4.6 How to convert a Number into a String with exactly 2
> decimal places?[/color]
[color=blue]
> ...[/color]
[color=blue]
>Adding a final note saying that the assigned
>Number.prototype.toFixed function is not equivalent to the
>original doesn't strike me as necessary.[/color]

The output of that function could be (a) equivalent to the original, or
(b) equivalent to the bug-freed original, or (c) different.

ISTM important to discriminate between (a)|(b) & (c); if possibly (c),
then I suggest calling the new function something slightly different,
such as toFixxed, and adding in comment the word similar.




[color=blue]
>The code used in section 4.15 has come in for a lot of comment lately.
>While it is not the code I would use for the task, the existing code
>is short, will work successfully in browsers that support innerHTML
>and the text includes the pertinent caveats. So I am inclined to
>leave it as it is for the time being, unless a strong feeling that
>it should be changed (baring in mind the need for brevity) is
>expressed.[/color]

However, ISTM that the wording might be reconsidered, and the code of
para 1 perhaps boxed.





I suggest that the FAQ could say that it classifies javascript versions
in three (four) ways
(a) Dead & gone (Javascript 1.0/1.1, IE & NS <=3, etc.?
(a') Netscape 4.7 & compatibles ?
(b) Elderly
(c) Current & compatibles
with
(a) being forgotten
(b) warnings of incompatibility, but not necessarily new
solutions, expected
(c) supported

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
Jim Ley
Guest
 
Posts: n/a
#3: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


On Wed, 7 Jan 2004 16:47:09 +0000, Dr John Stockton
<spam@merlyn.demon.co.uk> wrote:
[color=blue]
>If restructuring, one could start Sec.2 with a new 2.0 "What is
>javascript, and what is it for? - that would then absorb 2.6 & 2.7 &
>maybe 2.12 as subsubsections, and a slight enlargement of 2.8 sentence 3
>to cover "what for".
>
>"Javascript (and VBscript) can be used (a) in Web pages, which is the
>default assumption here; (b) in Intranet pages; (c) in Win32 with
>Windows Scripting Host, for general purposes; (d) in Web servers...; (e)[/color]

I'd ignore VBScript there. I'd also like to encourage SVG with it
being mentioned, SVG is probably more popular than WSH for javascript
use. (svg-developers mailing list for example often gets as many
non-faq js questions as here.) but expanding what for might be good.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jim Ley
Guest
 
Posts: n/a
#4: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


On Wed, 7 Jan 2004 02:51:35 -0000, "Richard Cornford"
<Richard@litotes.demon.co.uk> wrote:
[color=blue]
>He had already
>asked me if I was interested and I did volunteer, pointing out
>that because I am a dyslexic with a tendency to be long-winded[1][/color]

People elsewhere have said that I have the worst grammar they have
ever seen, so I don't think you can do any worse than me. Brevity can
be forced on you once you realise how many lines the post is after
processwenttxt.wsf is run.
[color=blue]
>I would appreciate any feedback, comments, suggestions, additions,
>alternatives, etc. that anyone feels like contributing prior to
>making any changes to the existing FAQ:-
>
><URL: http://jibbering.com/faq/ >[/color]

One possible suggestion was moving the domain of the FAQ to improve
search engine placement, e.g. http://javascript-faq.jibbering.com/
or similar, I can host whatever but currently only have domains
jibbering.com|org/spurn.org/svg-components.org to hand, it may not be
wise due to the risk losing any google love we've got (google
generally doesn't mind proper redirects to a new canonical url but...)
[color=blue]
> If anyone is in a position to express their opinion on the
> suitability of "JavaScript Pocket Reference" by David Flanagan
> for inclusion in the FAQ please do so.[/color]

Looking at it in Borders it's a broadly accurate pocket reference, if
you want such a thing it's suitable, I'm not sure how useful it
genuinely is though for someone looking to learn, but it does do what
it says on the tin.

[color=blue]
>By "include files" I assume you mean JS files referenced with the
>SRC attribute of script elements.[/color]

Would also need to mentione "xlink:href" here for other non-HTML
versions of script I think. (it's a FAQ elsewhere than here, and
could be usefully addressed in a few words)
[color=blue]
><draft>
> "These characters are illegal within ID attributes in the
> standard (x)HTML doctypes and javascript Identifiers, so you
> should try to avoid them as browsers may handle them
> incorrectly."
></draft>[/color]

I like this.
[color=blue]
>Successfully handling the manipulation of option elements in a select
>element is one of those things that probably deserves considerably
>more information than would fit well in a quick answer. There are
>always the design and fall-back/clean degradation issues in addition
>to the pure mechanics of creating and appending new Option elements.[/color]

It's amazing how much trouble this has been over the years...
[color=blue]
><FAQNONENTRY> - Jim, I can't see the new FAQ on the Web. ???[/color]

This reminds me, I need to change the script, or tell you something
else Richard, remind me if I forget.
[color=blue]
>I recall Jim mentioning one that supported document.all and
>document.layers at the same time.[/color]

Omniweb mentioned in
http://jibbering.com/faq/browsers.txt
[color=blue]
>Perhaps an opportunity to assert the general principal that if
>something can be done without JavaScript then it should be done
>without JavaScript.[/color]

I don't wholly agree with this, for example there are many things
which CSS fails more disastrously at than the well authored javascript
approach.
[color=blue]
>Then again it might just result in an extended argument about
>what the "best strategy" is.
>
>Anyone care to start the ball rolling?[/color]

"Don't do anything that stops people accessing your content/using your
site..."

There's my notes so far...

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

HikksNotAtHome
Guest
 
Posts: n/a
#5: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


In article <btfs7p$5gs$1$8300dec7@news.demon.co.uk>, "Richard Cornford"
<Richard@litotes.demon.co.uk> writes:
[color=blue]
>The second suggestion strikes me as proposing an entry in section
>4 that explains how to enable error reporting on at least the
>major browsers. Possibly with references to debuggers (though
>venkman is already referenced in section 3.2).
>
>As usual that is not often specifically asked as a question but
>the information is frequently posted in replies so it probably
>does deserve consideration for a place in section 4.[/color]

Another way to enable error messages in IE6:

Double click the Yellow ! in the lower left corner
Check the "Always display this message when an error occurs in the page"
checkbox.

With the way that MS has changed the path to enable/disabling it in
IE4/5/5.5/6, the above seems to be a simpler way to tell someone how to enable
the error messages.
[color=blue]
>if(document.all && !document.getElementById) {
> document.getElementById = function(id) {
> return document.all[id];
> }
>}[/color]

<--snip-->
[color=blue]
> I wonder whether including this is a good idea. I would handle
> IDed element retrieval with a specific function that either
> handled the fall-back from getElementById itself or had been
> set up during configuration to handle the fall-back. I generally
> don't like attempts to "normalise" browsers to a homogenised DOM.
>
> Opinions?[/color]

I don't see where thats normalising the browser. To me, it simply makes it
simpler to write scripts that fallback to IE4 instead of back to IE5 (unless
its found to be defective in IE4 somewhere) by defining a function that works
in IE4. Even with that snippet, the object detection routines should still be
used to ensure that what you are trying to do works. It just seems easier than
something like this:

if (document.getElementById){
//statements here
}
else if (document.all){
//same statements here but using document.all instead of
// document.getElementById
}

<--snip-->
[color=blue]
>4.38 will have to stay as it is unless Laurent (or someone else)
>comes up with an additional sentence (probably literally). And I
>suspect that the subject could not be usefully addressed in just
>one sentence, or any statement that was sufficiently short.[/color]

One thing that I have found out about Jims HTTPRequest page. I started
tinkering with it on a whim, and found out (via Martin Honnen, <URL:
http://tinyurl.com/2f2hc /> is to the thread where he made it work in Mozilla
for me. Not in the FAQ but if the FAQ links to a page that explains something,
shouldn't we be able to critique that page as well? (Sorry Jim)

<--snip-->
[color=blue]
><FAQ**TRY>
>type="text/javascript" in favor of language="javascript"
></FAQ**TRY>
>
>Not sure on a wording, but its seen a lot here :-(
>
></quote>
>
>This certainly is frequently mentioned so it might deserve an entry.
>
>So would the section 4 question be "How do I write HTML 4 valid
>script tags?" or "How do I write script tags?"? With the latter
>having to go into more detail on the LANGUAGE attribute (and
>possibly language version numbers and their associated problems)[/color]

"Should I use the language attribute or the type attribute in my script tags?"

And as they say, thats my 2 cents worth of thoughts. Although I am not as
verbose, my tendency is in the opposite direction and probably not verbose
enough.
--
Randy
Dr John Stockton
Guest
 
Posts: n/a
#6: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <3ffc84f8.92760432@news.cis.dfn.de>, seen in
news:comp.lang.javascript, Jim Ley <jim@jibbering.com> posted at Wed, 7
Jan 2004 22:56:04 :-[color=blue]
>[color=green]
>> If anyone is in a position to express their opinion on the
>> suitability of "JavaScript Pocket Reference" by David Flanagan
>> for inclusion in the FAQ please do so.[/color]
>
>Looking at it in Borders it's a broadly accurate pocket reference, if
>you want such a thing it's suitable, I'm not sure how useful it
>genuinely is though for someone looking to learn, but it does do what
>it says on the tin.[/color]

Don't underestimate the advantage of it being only 175*107*8 mm and
corresponding weight. As a source of reminder, it's very handy; for
example if (after experience on other languages, one wants to discover
why Math.trunc does not work as expected (trunc is spelt floor in JS).
Just "(has pocket version)" would suffice.

If that was the Kingston Borders, pray mail me where to look in it; I
prefer Dillons there.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Delphi 3 Turnpike 4 ©
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.html> news:borland.* Guidelines
Richard Cornford
Guest
 
Posts: n/a
#7: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"HikksNotAtHome" <hikksnotathome@aol.com> wrote in message
news:20040107234953.06226.00002313@mb-m19.aol.com...[color=blue][color=green]
>>... an entry in section 4 that explains how to enable error
>>reporting on at least the major browsers. ...[/color][/color]
<snip>[color=blue]
>
>Another way to enable error messages in IE6:
>
>Double click the Yellow ! in the lower left corner
>Check the "Always display this message when an error occurs in
>the page" checkbox.
>
>With the way that MS has changed the path to enable/disabling
>it in IE4/5/5.5/6, the above seems to be a simpler way to tell
>someone how to enable the error messages.[/color]

I was thinking much the same. I would be worth quickly mentioning that
it was also available for activation under one of the menus but paths
through menus and dialogs are not as easy to describe (especially as
text).

I would also favour describing typing "javascript:" into the location
bar on Netscape/Mozilla/Gecko browsers rather than going into details on
the menus and preferences dialogs.
[color=blue][color=green]
>>if(document.all && !document.getElementById) {
>> document.getElementById = function(id) {
>> return document.all[id];
>> }
>>}[/color][/color]
<snip>[color=blue][color=green]
>>I wonder whether including this is a good idea. I would
>>handle IDed element retrieval with a specific function
>>that either handled the fall-back from getElementById
>>itself or had been set up during configuration to handle
>>the fall-back. I generally don't like attempts to
>>"normalise" browsers to a homogenised DOM.
>>
>> Opinions?[/color]
>
>I don't see where thats normalising the browser. To me, it
>simply makes it simpler to write scripts that fallback to[color=green]
>>IE4 instead of back to IE5[/color][/color]

Well, its just one feature so it is a bit extreme to call it
normalising, but it is a step (albeit a small one) in that direction.
[color=blue]
>(unless its found to be defective in IE4 somewhere)[/color]

I can only see this code failing to be equivalent to getElementById if
there are multiple elements with the same ID on a page, or when an
element has the same string assigned to its NAME attribute as has been
assigned to the ID of a different element. The first is invalid HTML
(which IE puts up with) and the second is actually a problem for some IE
implementations of getElementById anyway.
[color=blue]
>by defining a function that works in IE4. Even with that
>snippet, the object detection routines should still be
>used to ensure that what you are trying to do works. It
>just seems easier than something like this:
>
>if (document.getElementById){
> //statements here
>}
>else if (document.all){
> //same statements here but using document.all instead of
> // document.getElementById
>}[/color]

Yes its easier than that, but recognising that the task that needs to be
handled differently on different browsers is just the IDed element
retrieval would suggest that just that task could be handed off to a
separate dedicated function so there is no repetition of blocks of
statements in the branches for each condition.

As the above function is just an easy way of handling fall-back for
browsers that have a document.all collection but no getElementById
method I still don't want to give it a dedicated entry in section 4 (at
least without some discussion of similar fall-back for other known
browsers. On the other hand, see my proposal for 4.15 in my reply to Dr
John Stockton for one possible compromise.

<snip>[color=blue]
>shouldn't we be able to critique that page as well? (Sorry Jim)[/color]

Changing that page is outside of my remit. :)

<snip>[color=blue][color=green]
>>So would the section 4 question be "How do I write HTML 4 valid
>>script tags?" or "How do I write script tags?"? With the latter
>>having to go into more detail on the LANGUAGE attribute (and
>>possibly language version numbers and their associated problems)[/color]
>
>"Should I use the language attribute or the type attribute in my
>script tags?"[/color]
<snip>

Maybe "and/or" instead of "or". That would narrow the question down
quite a bit, and so make for a short answer. It would also be a very
(x)HTML browser specific answer. I was wondering whether it would be
practical to address Dr John Stockton's concerns about including files
within this entry, but that won't be possible if it is narrowed down to
just the attributes.

Hmm, I might just have to write some versions and see what people think.

Thanks for your thoughts.

Richard.


Richard Cornford
Guest
 
Posts: n/a
#8: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Jim Ley" <jim@jibbering.com> wrote in message
news:3ffc84f8.92760432@news.cis.dfn.de...
<snip>[color=blue][color=green]
>>He had already asked me if I was interested and I
>>did volunteer, pointing out that because I am a
>>dyslexic with a tendency to be long-winded.[/color]
>
>People elsewhere have said that I have the worst grammar
>they have ever seen, so I don't think you can do any worse
>than me.[/color]

The extent to which my grammar may be acceptable is more a result of
having articulate parents and decades of listening to BBC Radio 4 than
anything the British education system can claim credit for. I don't know
any formal English grammar rules, I don't recall any of my school
"English teachers" ever mentioning anything substantial relating to
their subject at all.
[color=blue]
>Brevity can be forced on you once you realise how
>many lines the post is after processwenttxt.wsf is run.[/color]

I am very aware of the risk (and consequences of) bloating the FAQ. :)

<snip>[color=blue]
>One possible suggestion was moving the domain of the FAQ to
>improve search engine placement, e.g.
> http://javascript-faq.jibbering.com/
>or similar, I can host whatever but currently only have domains
>jibbering.com|org/spurn.org/svg-components.org to hand, it may
>not be wise due to the risk losing any google love we've got
>(google generally doesn't mind proper redirects to a new canonical
>url but...)[/color]

When you where debating this with Dr John Stockton (on
microsoft.public.scripting.jscript as I recall) I did a google search
and the FAQ came out 4th, which didn't seem too bad (or as bad as Dr
John Stockton's attempt).
[color=blue][color=green]
>> If anyone is in a position to express their opinion on the
>> suitability of "JavaScript Pocket Reference" by David Flanagan
>> for inclusion in the FAQ please do so.[/color]
>
>Looking at it in Borders it's a broadly accurate pocket reference,
>if you want such a thing it's suitable, I'm not sure how useful it
>genuinely is though for someone looking to learn, but it does do
>what it says on the tin.[/color]

Maybe someone with the 2nd or 3rd edition of javascript: The Definitive
Guide might want an up to date reference without the rest of the book,
but I agree that it is not a book for learners of JavaScript. I am still
not inclined to include it.

<snip>[color=blue]
>This reminds me, I need to change the script, or tell you
>something else Richard, remind me if I forget.[/color]

OK.

<snip>[color=blue][color=green]
>>Perhaps an opportunity to assert the general principal that if
>>something can be done without JavaScript then it should be done
>>without JavaScript.[/color]
>
>I don't wholly agree with this, for example there are many things
>which CSS fails more disastrously at than the well authored
>javascript approach.[/color]

You are thinking of things like the CSS "alternative" to, say, image
rollover scripts that aren’t (yet) nearly as well supported as the
JavaScript approach? I was thinking more of things like using JavaScript
to detect the browsers and then choose a stylesheet to reference in link
elements (often with no default for when JavaScript is not available),
which is something I think is better addressed with CSS alone.
[color=blue][color=green]
>>Then again it might just result in an extended argument about
>>what the "best strategy" is.
>>
>>Anyone care to start the ball rolling?[/color]
>
>"Don't do anything that stops people accessing your
>content/using your site..."[/color]

In which "(or search engine robots)" cold be inserted after "people", if
they could be said to "use" a site.
[color=blue]
>There's my notes so far...[/color]

Thanks, I still have plenty to think about before settling on any final
changes.

Richard.


Richard Cornford
Guest
 
Posts: n/a
#9: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
news:krGF2THNgD$$EwK7@merlyn.demon.co.uk...
<snip>[color=blue]
>The most important thing is to indicate that the possibility
>exists, better than 2.8 does at present.[/color]

OK.
[color=blue]
>If restructuring, one could start Sec.2 with a new 2.0
>"What is javascript, and what is it for? - that would then
>absorb 2.6 & 2.7 & maybe 2.12 as subsubsections, and a slight
>enlargement of 2.8 sentence 3 to cover "what for".
>
>"Javascript (and VBscript) can be used ...[/color]
<snip>

I will have to mull that over a bit and consider Jim's suggestion of
mentioning SVG, but I have no intention of mentioning VBScript (I'll
leave that for VBScript groups).

<snip>[color=blue]
>Not necessarily as much as that in the FAQ itself. But a scan
>of the FAQ for include and for src finds nothing related. Perhaps
>no more need be said than the essence of
><URL: http://www.merlyn.demon.co.uk/js-other.htm#Inc >.[/color]

As I said, I was thinking SRC could get into an entry on writing formal
script tags, but Randy is interested in stressing the type V language
attribute aspect so I will have to see where that goes.
[color=blue][color=green]
>>That function returns 50 for inputs of +5 & -5; and 00 for 0.
>>
>> function LZ(x) {return(x<0||x>9?"":"0")+x} // for integers[/color]
>[color=green]
>>I wonder if that could/should be slipped in at the end of 4.6 as ...[/color][/color]
<snip>[color=blue]
>IMHO, the item needs to be evident in sec. 4 of the index;
>i.e. in Subject(4.6).modified or under a new Subject.[/color]

I will start pulling that together into a proposal for 4.6 shortly.

<snip>[color=blue]
>While Summer Time is not often asked about, it is quite
>often answered about.[/color]

True, but I was wondering if there might be something more often
asked/answered about Date. But if the point is channel people interested
in the Date object towards more information by reference then it isn't
vital which Date question is answered in the FAQ.
[color=blue]
>Qn : Why does date ( differencing | incrementing ) go wrong?
>Ans : Date is basically held as GMT, so date arithmetic across
> Summer Time transitions needs particular care. Examples :[/color]

GMT or UTC (strictly)?
[color=blue]
>(new Date('2004/11/01') - new Date('2004/10/01'))/864e5 // is 31.0416
>new Date(new Date('2004/10/01').getTime()+31*864e5).getDate() // is 31
>// Better examples may spontaneously appear.[/color]

spontaneously appear? :)
[color=blue]
>Note that that the term "Summer Time" usefully introduces the
>string "Time" for search-fodder.[/color]

In terms of the natural translation into English of the concept in other
languages (and its use in various English speaking cultures), is "summer
Time" preferable to "Daylight Saving Time" (either would introduce
"Time" as a search term)? It is not that easy for me to tell because I
habitually use "summer Time" in a UK context.
[color=blue]
>[color=green]
> >4.6 How to convert a Number into a String with exactly 2
> > decimal places?
> > ...[/color]
>[color=green]
>>Adding a final note saying that the assigned
>>Number.prototype.toFixed function is not equivalent
>>to the original doesn't strike me as necessary.[/color]
>
>The output of that function could be (a) equivalent to the
>original, or (b) equivalent to the bug-freed original, or (c)
>different.
>
>ISTM important to discriminate between (a)|(b) & (c); if
>possibly (c), then I suggest calling the new function something
>slightly different, such as toFixxed, and adding in comment the
>word similar.[/color]

Would you be satisfied with a JavaScript comment in the code block?

<snip>[color=blue][color=green]
>>The code used in section 4.15 has come in for a lot
>> of comment lately. ...[/color][/color]
<snip>[color=blue]
>However, ISTM that the wording might be reconsidered, and
>the code of para 1 perhaps boxed.[/color]

There are two separate sections of code in paragraph 1 (HTML and
JavaScript) and they seem to me to be too short to warrant a box of
their own. Re-wording is worth considering, how about:-

<draft>
4.15 How do I modify the current page in a browser?

Modern dynamic browsers (including IE4+ and NS6+) with the - innerHTML -
extension allow new HTML code to be assigned to the content of elements.
With original HTML such as <div id="anID">some content</div> the
contents of the div element could be replaced with:
document.getElementById("anID").innerHTML="Some <em>new<\/em> Content";

if((!document.getElementById) && document.all){
document.getElementById =
new Function("id", "return document.all[id];");
} // emulate getElementById on document.all only browsers.

if(document.getElementById){
DynWrite=new Function("id", "S",
"document.getElementById(id).innerHTML=S; return true");
}else{
DynWrite=new Function("return false;");
}

The above code is ineffective but (quietly) harmless on browsers that do
not support the required features. NS4 also allows some re-writing of
the current page but has serious issues and is not covered here. Also,
browsers are increasingly supporting standardised methods for creating
and inserting new elements/nodes into the DOM tree, which can be used to
similar effect.

<existing links to innerHTML info>
<new link to W3C core DOM refs., or a good page on
createElement/appendChild approach (suggestions?)>
</draft>

Slightly longer over all.

I said that I would not re-write Jim's code but the above is
functionally equivalent, slightly shorter and provides an opportunity to
slip Randy's IE4 support for getElementById (though in a Function
constructor form) in without dedicating a separate question to it.

I have also added a word on the W3C DOM createElement approach.
Hopefully that will placate some of the objectors to the use of
innerHTML, one of whom might care to find a good page to reference on
the subject (rather than the W3C specs).
[color=blue]
> I suggest that the FAQ could say that it classifies javascript
>versions in three (four) ways
> (a) Dead & gone (Javascript 1.0/1.1, IE & NS <=3, etc.?
> (a') Netscape 4.7 & compatibles ?
> (b) Elderly
> (c) Current & compatibles
> with
> (a) being forgotten
> (b) warnings of incompatibility, but not necessarily new
> solutions, expected
> (c) supported[/color]

That looks like it could be a footnote to section 4, I will think about
it.

Thanks for the (and future) feedback.

Richard.


Dr John Stockton
Guest
 
Posts: n/a
#10: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <btl7ae$4oj$1$8300dec7@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Richard@litotes.demon.co.uk> posted at Fri, 9 Jan 2004 03:31:25 :-[color=blue]
>
>I can only see this code failing to be equivalent to getElementById if
>there are multiple elements with the same ID on a page, or when an
>element has the same string assigned to its NAME attribute as has been
>assigned to the ID of a different element. The first is invalid HTML
>(which IE puts up with) and the second is actually a problem for some IE
>implementations of getElementById anyway.[/color]

A warning along the lines of "Here, it is safest to have the ID
different from any other ID or NAME on the page; it is generally unwise
to repeat identifications unnecessarily, except for experts." might
suffice.

That's not a bad rule in general; for example, if a page has two
distinct instances of a matching label in circumstances where all
browsers can tell them apart, it is still possible for the programmer to
start editing the wrong one.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Dr John Stockton
Guest
 
Posts: n/a
#11: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <btl7ak$4on$1$8300dec7@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Richard@litotes.demon.co.uk> posted at Fri, 9 Jan 2004 03:31:32 :-[color=blue]
>"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
>news:krGF2THNgD$$EwK7@merlyn.demon.co.uk...[/color]

[color=blue][color=green]
>>Qn : Why does date ( differencing | incrementing ) go wrong?
>>Ans : Date is basically held as GMT, so date arithmetic across
>> Summer Time transitions needs particular care. Examples :[/color]
>
>GMT or UTC (strictly)?[/color]

Strictly, I believe, UT. But that looks like a misprint for UTC. UTC
has leap seconds, and is therefore inappropriate for ordinary computer
work, where they are ignored. GMT is very widely understood, with a
meaning matching the circumstances. No ordinary computer keeps time
accurately enough for the difference between any "similar" scales to
matter. The differences that matter are caused by Time Zone, Summer
Time, and Just Plain Being Wrongly Set (and, for a few, by the
difference between sidereal & solar time, which is about one part in
365).

Therefore, I tend to use GMT in text, and the UTC functions in code; it
has the advantage that I can search independently for code & text
references.

However, considering automated searches, if the FAQ says enough about
date to include one of GMT & UTC, it should have both : "... held as
GMT/UTC, so ..." conveys appropriate ambiguity. For the knowledgeable,
perhaps include /UT.
[color=blue][color=green]
>>(new Date('2004/11/01') - new Date('2004/10/01'))/864e5 // is 31.0416
>>new Date(new Date('2004/10/01').getTime()+31*864e5).getDate() // is 31
>>// Better examples may spontaneously appear.[/color]
>
>spontaneously appear? :)[/color]

In the newsgroup. There have been many in the past.


[color=blue][color=green][color=darkred]
>> >4.6 How to convert a Number into a String with exactly 2
>> > decimal places?
>> > ...[/color]
>>[color=darkred]
>>>Adding a final note saying that the assigned
>>>Number.prototype.toFixed function is not equivalent
>>>to the original doesn't strike me as necessary.[/color]
>>
>>The output of that function could be (a) equivalent to the
>>original, or (b) equivalent to the bug-freed original, or (c)
>>different.
>>
>>ISTM important to discriminate between (a)|(b) & (c); if
>>possibly (c), then I suggest calling the new function something
>>slightly different, such as toFixxed, and adding in comment the
>>word similar.[/color]
>
>Would you be satisfied with a JavaScript comment in the code block?[/color]

Yes; it has the advantage of possibly appearing in the code used.
[color=blue]
>
><snip>[color=green][color=darkred]
>>>The code used in section 4.15 has come in for a lot
>>> of comment lately. ...[/color][/color]
><snip>[color=green]
>>However, ISTM that the wording might be reconsidered, and
>>the code of para 1 perhaps boxed.[/color]
>
>There are two separate sections of code in paragraph 1 (HTML and
>JavaScript) and they seem to me to be too short to warrant a box of
>their own. Re-wording is worth considering, how about:-
>
><draft>
>4.15 How do I modify the current page in a browser?
>
>Modern dynamic browsers (including IE4+ and NS6+) with the - innerHTML -
>extension allow new HTML code to be assigned to the content of elements.
>With original HTML such as <div id="anID">some content</div> the
>contents of the div element could be replaced with:
>document.getElementById("anID").innerHTML="Some <em>new<\/em> Content";
>
>if((!document.getElementById) && document.all){
> document.getElementById =
> new Function("id", "return document.all[id];");
>} // emulate getElementById on document.all only browsers.
>
>if(document.getElementById){
> DynWrite=new Function("id", "S",
> "document.getElementById(id).innerHTML=S; return true");
>}else{
> DynWrite=new Function("return false;");
>}
>
>The above code is ineffective but (quietly) harmless on browsers that do
>not support the required features.[/color]

I do NOT like quietly ineffective code. Failing to work CANNOT be
assumed harmless by a FAQ maintainer; that is a programmer or page-
designer decision.

But ISTM that by replacing }else{ ... } in the above with something
like

}
if (!DynWrite) {
alert("Element replacement not available in this browser.\n" +
"Display likely to be partially incorrect.")
DynWrite=new Function("return false;")
}


then a clear warning is given to the mere reader of the FAQ, and is
evident to the copy'n'paster of the material. It is also obvious that a
reader of the page may get an alert, and obvious how to prevent that.

The additional overhead of if (!DynWrite) as opposed to else
must be insignificant.


That which is at present in the FAQ works for me, presuming that my
holidays.htm works for near enough everyone; elsewhere, I use something
similar. I would change to new FAQ code if I knew that the new code
works with MSIE4 and with at least as many later browsers as the old.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jim Ley
Guest
 
Posts: n/a
#12: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


On Fri, 9 Jan 2004 03:31:32 -0000, "Richard Cornford"
<Richard@litotes.demon.co.uk> wrote:
[color=blue]
>"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message[/color]
[color=blue]
><existing links to innerHTML info>
><new link to W3C core DOM refs., or a good page on
>createElement/appendChild approach (suggestions?)>
></draft>[/color]

I'm actually quite reluctant to incude createElement/setAttribute as
they're not needed in current browsers, and future browsers will be
namespace aware so the namespace aware versions such as
createElementNS will be required, and teaching createElement will just
confuse people even more.

Of course I'm well known for not being a fan of DOM 1, and the amount
of questions it generates is the main reason.
[color=blue]
>I said that I would not re-write Jim's code[/color]

rewrite any of it, it's at least 4 years old, and grew out of a need
to support NN4, change it however!

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jim Ley
Guest
 
Posts: n/a
#13: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


On Thu, 8 Jan 2004 15:20:50 +0000, Dr John Stockton
<spam@merlyn.demon.co.uk> wrote:
[color=blue]
>Don't underestimate the advantage of it being only 175*107*8 mm and
>corresponding weight. As a source of reminder, it's very handy; for
>example if (after experience on other languages, one wants to discover
>why Math.trunc does not work as expected (trunc is spelt floor in JS).
>Just "(has pocket version)" would suffice.[/color]

I agree, as it is by an author who we do acknowledge and does do what
it says, adding that would be fine.
[color=blue]
>If that was the Kingston Borders, pray mail me where to look in it; I
>prefer Dillons there.[/color]

ER, it was a Vancouver Borders... IIRC Kingston had them upstairs on
the opposite side from the cafe bit in the 2nd bay from the left.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jim Ley
Guest
 
Posts: n/a
#14: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


On Fri, 9 Jan 2004 03:31:28 -0000, "Richard Cornford"
<Richard@litotes.demon.co.uk> wrote:
[color=blue]
>When you where debating this with Dr John Stockton (on
>microsoft.public.scripting.jscript as I recall)[/color]

Was it, I'm not currently reading there, although I did for awhile
again on the wine covered laptop, I guess it could've been then.
[color=blue]
> I did a google search
>and the FAQ came out 4th, which didn't seem too bad (or as bad as Dr
>John Stockton's attempt).[/color]

I'd've thought http://javascript-faq.jibbering.com/ that kept the
current google love of the FAQ would get even better than that, but
I'm not sure it's really worth the trouble, especially as it's extra
risk of me forgetting to set up the vhosts if I change/reinstall
servers and server is getting a new disk real soon now, well when I
can get one shipped down there, and get it nstalled it, it's currently
very ill, new server sometime soon. Okay, not really a new server, a
wine covered laptop...

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jim Ley
Guest
 
Posts: n/a
#15: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


On 08 Jan 2004 04:49:53 GMT, hikksnotathome@aol.com (HikksNotAtHome)
wrote:
[color=blue]
>One thing that I have found out about Jims HTTPRequest page. I started
>tinkering with it on a whim, and found out (via Martin Honnen, <URL:
>http://tinyurl.com/2f2hc /> is to the thread where he made it work in Mozilla
>for me.[/color]

Hey, c'mon I wrote it almost 2 years ago, and I'm still not interested
enough in mozilla outside web security to bother looking into it.
I'll update it to point to the thread, at some point, if I find some
bandwidth.
[color=blue]
> Not in the FAQ but if the FAQ links to a page that explains something,
>shouldn't we be able to critique that page as well? (Sorry Jim)[/color]

My pages can always be critiqued, they're basically rubbish, not only
that, but patches are always welcome, and sometimes even apply them
:-)

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jim Ley
Guest
 
Posts: n/a
#16: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


On Fri, 9 Jan 2004 03:31:25 -0000, "Richard Cornford"
<Richard@litotes.demon.co.uk> wrote:
[color=blue][color=green]
>>shouldn't we be able to critique that page as well? (Sorry Jim)[/color]
>
>Changing that page is outside of my remit. :)[/color]

Nah, you've got write access to it, feel free!

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jim Ley
Guest
 
Posts: n/a
#17: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


On Fri, 9 Jan 2004 20:00:08 +0000, Dr John Stockton
<spam@merlyn.demon.co.uk> wrote:
[color=blue]
>I do NOT like quietly ineffective code.[/color]

then you shouldn't be authoring for the web, your code has to be able
to cope with that situation, as it's always one of the options.
[color=blue]
> Failing to work CANNOT be
>assumed harmless by a FAQ maintainer; that is a programmer or page-
>designer decision.[/color]

Then there's no possible code we could use.
[color=blue]
> alert("Element replacement not available in this browser.\n" +
> "Display likely to be partially incorrect.")[/color]

So making completely unwarranted assumptions about the existance of
alert... Also of course it's completely un-understandable to users.
[color=blue]
>then a clear warning is given to the mere reader of the FAQ, and is
>evident to the copy'n'paster of the material.[/color]

The warning I believe is more than sufficient, I'm still reluctant to
have 4.15 in at all.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

John G Harris
Guest
 
Posts: n/a
#18: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


In article <8LHDu3KIhw$$Ewb4@merlyn.demon.co.uk>, Dr John Stockton
<spam@merlyn.demon.co.uk> writes[color=blue]
>JRS: In article <btl7ak$4on$1$8300dec7@news.demon.co.uk>, seen in
>news:comp.lang.javascript, Richard Cornford
><Richard@litotes.demon.co.uk> posted at Fri, 9 Jan 2004 03:31:32 :-[/color]
<snip>[color=blue][color=green]
>>GMT or UTC (strictly)?[/color]
>
>Strictly, I believe, UT. But that looks like a misprint for UTC.[/color]
<snip>

Strictly, none of these. You will find a refreshingly clear, as well as
accurate, account of calendar and time systems at

<URL:http://www.npl.co.uk/time/time_scales.html>

Javascript date objects use a rule for allocating each second to a
particular minute/hour/day/month/year that hasn't got an official name.
Approximate local time is as good a description as any.

John
--
John Harris
Richard Cornford
Guest
 
Posts: n/a
#19: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
news:8LHDu3KIhw$$Ewb4@merlyn.demon.co.uk...
<snip>[color=blue][color=green][color=darkred]
>>>... : Date is basically held as GMT, ...[/color][/color][/color]
<snip>[color=blue][color=green]
> >GMT or UTC (strictly)?[/color]
>
>Strictly, I believe, UT. But that looks like a misprint for
>UTC. UTC has leap seconds, and is therefore inappropriate for
>ordinary computer work, ...[/color]
<snip>[color=blue]
>However, considering automated searches, if the FAQ says enough
>about date to include one of GMT & UTC, it should have both :
>"... held as GMT/UTC, so ..." conveys appropriate ambiguity.
> For the knowledgeable, perhaps include /UT.[/color]

The spec says:-
<quote cite="ECMA 262 3rd edition">
15.9.1.1 Time Range
Time is measured in ECMAScript in milliseconds since 01 January,
1970 UTC. Leap seconds are ignored. It is assumed that there are
exactly 86,400,000 milliseconds per day. ...

...

The exact moment of midnight at the beginning of 01 January, 1970
UTC is represented by the value +0.
</quote>

But I like "conveys appropriate ambiguity" (and agree that GMT might be
useful for searching), though I probably will put UTC first.

<snip>[color=blue][color=green]
>>The above code is ineffective but (quietly) harmless on browsers
>>that do not support the required features.[/color]
>
>I do NOT like quietly ineffective code. Failing to work CANNOT be
>assumed harmless by a FAQ maintainer; that is a programmer or page-
>designer decision.[/color]

I don't like quietly harmless code either, I want code to actively know
that what it intends to do will fail or has failed, so it is in a
position to fall-back/cleanly degrade under control. But when it comes
to using JavaScript for inserting content into HTML that becomes quite
involved, and often very specific to the problem situation.

I added the comment because I though that readers of the FAQ might
appreciate being tipped of that the code is not a panacea. But there
isn't a content inserting panacea as there are numerous browsers that
are just not that dynamic (and, of course, nothing can be inserted
without JavaScript[1]).
[color=blue]
>But ISTM that by replacing }else{ ... } in the above
>with something like
>
> }
> if (!DynWrite) {
> alert("Element replacement not available in this browser.\n" +
> "Display likely to be partially incorrect.")
> DynWrite=new Function("return false;")
> }[/color]

Unfortunately it is not a simple as that. The branch that generates
the - return false; - function is guaranteed to never be able to insert
content (because it has no mechanism for retrieving the element
references) but the other branch is a long way from guaranteed success.
On Opera 6, for example, it will assign a new string property to the
element, but that will not alter the page or DOM tree in any way
(harmless, but ineffective).
[color=blue]
>then a clear warning is given to the mere reader of the FAQ,[/color]

Which is what I was attempting.
[color=blue]
>and is evident to the copy'n'paster of the material. It is
>also obvious that a reader of the page may get an alert, and
>obvious how to prevent that.[/color]

I suspect that the copt'n'paste merchants actively don't want to
understand what they are doing (witness George Hester) and are likely to
leave the alert in place.
[color=blue]
>else The additional overhead of if (!DynWrite) as opposed to
>must be insignificant.[/color]

For the logic of the situation the - else - seems fine to me.
[color=blue]
>That which is at present in the FAQ works for me,[/color]

My version of Jim's code is logically identical. It will behave
identically to the original. The only difference is that because it uses
Randy's getElementById emulation to create a document.getElementById
function on IE4 (and maybe others) it will produce a knock-on effect of
convincing other scripts that misguidedly make inferences about features
beyond getElementById based on its existence that they are looking at a
browser similar to IE 5+. But as we recommend against object inference
probably that is an effect that does not need to be worried about.
[color=blue]
>presuming that my holidays.htm works for near enough
>everyone; elsewhere, I use something similar.[/color]

It's a page design decision, and it's yours to make. The script (Jim's
and mine) will work on JavaScirpt capable browsers that support the
innerHTML extension. That is the largest sub-set of browsers on which it
is possible to insert content dynamically.
[color=blue]
>I would change to new FAQ code if I knew that the new code
>works with MSIE4 and with at least as many later browsers as
>the old.[/color]

There is no reason that it should not work on exactly as many browsers
as the previous version because it doesn't do anything any differently.

Richard.

[1] Except that CSS has some content inserting behaviour in its latter
versions, but not implemented in many browsers yet. And if CSS is
optional then any content inserted with it also has to be optional. (But
much the same is true of JavaScript.)


Richard Cornford
Guest
 
Posts: n/a
#20: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Jim Ley" <jim@jibbering.com> wrote in message
news:3fff074b.257195237@news.cis.dfn.de...
<snip>[color=blue]
>I'm actually quite reluctant to incude createElement/setAttribute
>as they're not needed in current browsers, and future browsers
>will be namespace aware so the namespace aware versions such as
>createElementNS will be required, and teaching createElement
>will just confuse people even more.[/color]

That is a very good point. I was recently thinking about the NS versions
of the core DOM functions in relation to the occasionally promoted
suggestion that Core DOM should be used instead of HTML DOM methods
because it would facilitate future-compatibility with XHTML
implementations. But for XHTML the code is going to have to be
re-written for the NS functions anyway, making the future compatibility
argument a bit hollow.

I don't have a problem with dropping that last sentence (and the
reference). So it's over to the DOM supporters to convince me to include
it. :)
[color=blue]
>Of course I'm well known for not being a fan of DOM 1, and
>the amount of questions it generates is the main reason.
>[color=green]
>>I said that I would not re-write Jim's code[/color]
>
>rewrite any of it, it's at least 4 years old, and grew out of
>a need to support NN4, change it however![/color]

Ok, in that case the Function constructors are going to be changed to
function expressions. Which means that Randy's getElementById emulation
will get to revert to its original form. As I understand it the Function
constructors are to avoid syntax errors in ancient language version, and
if we stop actively supporting Netscape 4 it doesn't seem unreasonable
to assume that the code will never be seen by even older browsers.

Richard.


Dr John Stockton
Guest
 
Posts: n/a
#21: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <btqcpe$qmq$1$8300dec7@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Richard@litotes.demon.co.uk> posted at Sun, 11 Jan 2004 02:35:15 :-[color=blue]
>"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
>news:8LHDu3KIhw$$Ewb4@merlyn.demon.co.uk...[/color]
[color=blue]
>The spec says:-
><quote cite="ECMA 262 3rd edition">
>15.9.1.1 Time Range
> Time is measured in ECMAScript in milliseconds since 01 January,
> 1970 UTC.[/color]

Should of course include "the start of" or "0h" or similar;
1 ms from 1 Jan 70 was at 00:00:00.001 in 2 Jan 1970.
[color=blue]
> Leap seconds are ignored. It is assumed that there are
> exactly 86,400,000 milliseconds per day. ...[/color]

That's certainly a wrong thing to put, of course, to say "per
UTC day" would at least be consistent.
[color=blue]
> ...
>
> The exact moment of midnight at the beginning of 01 January, 1970
> UTC is represented by the value +0.
></quote>[/color]

That is acceptable; but the time scale that it defines is not UTC
(however, I suspect that UTC may not have been defined in 1970).

[color=blue]
>But I like "conveys appropriate ambiguity" (and agree that GMT might be
>useful for searching), though I probably will put UTC first.[/color]

[color=blue]
>I added the comment because I though that readers of the FAQ might
>appreciate being tipped of that the code is not a panacea. But there
>isn't a content inserting panacea as there are numerous browsers that
>are just not that dynamic (and, of course, nothing can be inserted
>without JavaScript[1]).
>[color=green]
>>But ISTM that by replacing }else{ ... } in the above
>>with something like
>>
>> }
>> if (!DynWrite) {
>> alert("Element replacement not available in this browser.\n" +
>> "Display likely to be partially incorrect.")
>> DynWrite=new Function("return false;")
>> }[/color]
>
>Unfortunately it is not a simple as that. The branch that generates
>the - return false; - function is guaranteed to never be able to insert
>content (because it has no mechanism for retrieving the element
>references) but the other branch is a long way from guaranteed success.
>On Opera 6, for example, it will assign a new string property to the
>element, but that will not alter the page or DOM tree in any way
>(harmless, but ineffective).[/color]

It is not harmless if the coder put a false statement in a Div expecting
it to be over-written.

ISTM that an inability to warn in some circumstances does not justify
failing to warn in circumstances when the failure is easily detected.
But if there is any code or comment or text warning in the FAQ, then
code plus comment plus text should between them warn of all known
possible failures, even if it is necessary to resort to text like "in
some browsers this fails undetectably".
[color=blue][color=green]
>>then a clear warning is given to the mere reader of the FAQ,[/color]
>
>Which is what I was attempting.
>[color=green]
>>and is evident to the copy'n'paster of the material. It is
>>also obvious that a reader of the page may get an alert, and
>>obvious how to prevent that.[/color]
>
>I suspect that the copt'n'paste merchants actively don't want to
>understand what they are doing (witness George Hester) and are likely to[/color]
^^^^^^^^^^^^^
No; until I see reason to believe that his style has changed to conform
with Usenet standards, I'll not witness that; but it's easy to believe.
[color=blue]
>leave the alert in place.[/color]

In that case they should find it in testing, if it is a well-tested
site; or someone else will find it for them. Even code in a FAQ should
be scrutinised before use, and preferably understood.

After all, the existing code has side-effects; it replaces any previous
value in DocDom, GetRef, etc. A user should give himself an opportunity
to notice that.



[color=blue]
>[1] Except that CSS has some content inserting behaviour
> ...[/color]

I think you can reasonably safely say that nothing can be inserted by
javascript in a browser which is not running javascript.


Perhaps the example in the FAQ should have HTML resembling
<div ID=XXX>This should not remain here.</div>.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Randy Webb
Guest
 
Posts: n/a
#22: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


Dr John Stockton wrote:[color=blue]
> JRS: In article <btqcpe$qmq$1$8300dec7@news.demon.co.uk>, seen in
> news:comp.lang.javascript, Richard Cornford
> <Richard@litotes.demon.co.uk> posted at Sun, 11 Jan 2004 02:35:15 :-
>[color=green]
>>"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
>>news:8LHDu3KIhw$$Ewb4@merlyn.demon.co.uk...[/color][/color]

<--snip-->
[color=blue][color=green]
>>Unfortunately it is not a simple as that. The branch that generates
>>the - return false; - function is guaranteed to never be able to insert
>>content (because it has no mechanism for retrieving the element
>>references) but the other branch is a long way from guaranteed success.
>>On Opera 6, for example, it will assign a new string property to the
>>element, but that will not alter the page or DOM tree in any way
>>(harmless, but ineffective).[/color]
>
>
> It is not harmless if the coder put a false statement in a Div expecting
> it to be over-written.[/color]

If a coder puts code in that he expects to be over-written, then he
almost deserves what he gets for not realizing that it won't be
over-written.

How would you over-write it in non-js browsers?

To put a false statement in expecting it to be over-written is a fallacy
on the web-authors part.

<--snip-->
[color=blue]
>
>
> Perhaps the example in the FAQ should have HTML resembling
> <div ID=XXX>This should not remain here.</div>.
>[/color]

Why? The idea is not to depend on javascript, but to use it to
complement the page. So why would you want to start with text that
shouldn't remain in the absence of client-side scripting?

--
Randy

Jim Ley
Guest
 
Posts: n/a
#23: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


On Sun, 11 Jan 2004 02:35:22 -0000, "Richard Cornford"
<Richard@litotes.demon.co.uk> wrote:
[color=blue]
>As I understand it the Function
>constructors are to avoid syntax errors in ancient language version, and
>if we stop actively supporting Netscape 4 it doesn't seem unreasonable
>to assume that the code will never be seen by even older browsers.[/color]

Well the problem with syntax errors is they're wholly undetectable by
any logical method so make degradation hard, and impose the error on
users, of course it'll have to be very common to such folk so it's not
too bad.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Steve Allen
Guest
 
Posts: n/a
#24: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


Dr John Stockton <spam@merlyn.demon.co.uk> wrote in message news:<NAW$8PAy+ZAAFwrH@merlyn.demon.co.uk>...[color=blue]
> JRS: In article <btqcpe$qmq$1$8300dec7@news.demon.co.uk>, seen in
> news:comp.lang.javascript, Richard Cornford
> <Richard@litotes.demon.co.uk> posted at Sun, 11 Jan 2004 02:35:15 :-[color=green]
> >"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
> >news:8LHDu3KIhw$$Ewb4@merlyn.demon.co.uk...[/color][/color]
[color=blue][color=green]
> > Time is measured in ECMAScript in milliseconds since 01 January,
> > 1970 UTC.[/color][/color]

Regarding the meaning of the date 1970-01-01T00:00:00 I recommend
reading
http://www.ucolick.org/~sla/leapsecs...bib.html#POSIX
and down a bit further at
http://www.ucolick.org/~sla/leapsecs...tml#POSIXepoch
[color=blue][color=green]
> > Leap seconds are ignored. It is assumed that there are
> > exactly 86,400,000 milliseconds per day. ...[/color]
>
> That's certainly a wrong thing to put, of course, to say "per
> UTC day" would at least be consistent.[/color]

No, all forms of day other than UTC days always have exactly 86400
seconds. It is *only* a UTC day which can have other than 86401 (or
86399) seconds. This is why I assert that most system clocks are
actually counting mean solar seconds, and not SI seconds.
[color=blue]
> That is acceptable; but the time scale that it defines is not UTC
> (however, I suspect that UTC may not have been defined in 1970).[/color]

UTC was defined in 1970, but the meaning and properties were notably
different from the current ones. See
http://www.ucolick.org/~sla/leapsecs...cales.html#UTC
http://www.ucolick.org/~sla/leapsecs/dutc.html#UTC

Also, before 1972 the available time signals in some countries were
sometimes SAT instead of UTC, and they were usually called GMT. About
GMT see
http://www.ucolick.org/~sla/leapsecs...cales.html#GMT
and there is also a reference to SAT in there.

In any case, it is not reasonable to expect strictly monotonic time
stamps for most systems operating in that era, and it is dangerous to
assert an overly-precise meaning to the epoch.
Richard Cornford
Guest
 
Posts: n/a
#25: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Jim Ley" <jim@jibbering.com> wrote in message
news:3fff0abf.258078787@news.cis.dfn.de...[color=blue][color=green]
>>Don't underestimate the advantage of it being only 175*107*8 mm
>>and corresponding weight. As a source of reminder, ...[/color][/color]
<snip>[color=blue]
>I agree, as it is by an author who we do acknowledge and does
>do what it says, adding that would be fine.[/color]
<snip>

So something like:-
<draft>
3.1 What books cover javascript?
The best book currently available is: javascript: The Definitive
Guide, 4th Edition By David Flanagan ISBN:0-596-00048-0 (Also by
David Flanagan: JavaScript Pocket Reference, 2nd Edition.
ISBN 0-596-00411-7 for language and API reference alone).
</draft>

(Note: the ISBN is updated from the earlier references, which I assume
were details of the first edition (I checked the O'Reilly web site so it
should be accurate)).

Richard.


Richard Cornford
Guest
 
Posts: n/a
#26: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Jim Ley" <jim@jibbering.com> wrote in message
news:400290c8.62428487@news.cis.dfn.de...[color=blue][color=green]
>>As I understand it the Function constructors are to
>>avoid syntax errors in ancient language version, and
>>if we stop actively supporting Netscape 4 it doesn't
>>seem unreasonable to assume that the code will never
>>be seen by even older browsers.[/color]
>
>Well the problem with syntax errors is they're wholly
>undetectable by any logical method so make degradation
>hard, and impose the error on users, of course it'll have
>to be very common to such folk so it's not too bad.[/color]

Syntax errors are a problem, as the conditions cannot be reliably tested
for or recovered from and they are potentially very public failures. I
would not recommend the use of try-catch on the internet because it is
almost certain that code using it will be exposed to Netscape 4 or IE 4
and will produce syntax errors in either. But there must be a point in
the future when there is no expectation that code using try-catch will
be exposed to an unsupporting browser and they can be considered safe to
use. It is my feeling that function expressions may have arrived at that
point.

I also notice that the Function constructor was introduce in JavaScript
1.1 while nested functions are JavaScript 1.2 and function expressions
seem to become available from that version on (though they do not appear
to be in ECMA 262 until the 3rd edition). Granted support for the
Function constructor can be ascertained prior to its use so the risk is
of run-time errors if not verified instead of syntax errors.

Richard.


Randy Webb
Guest
 
Posts: n/a
#27: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


Richard Cornford wrote:
[color=blue]
> "Jim Ley" <jim@jibbering.com> wrote in message
> news:3fff0abf.258078787@news.cis.dfn.de...
>[color=green][color=darkred]
>>>Don't underestimate the advantage of it being only 175*107*8 mm
>>>and corresponding weight. As a source of reminder, ...[/color][/color]
>
> <snip>
>[color=green]
>>I agree, as it is by an author who we do acknowledge and does
>>do what it says, adding that would be fine.[/color]
>
> <snip>
>
> So something like:-
> <draft>
> 3.1 What books cover javascript?
> The best book currently available is: javascript: The Definitive
> Guide, 4th Edition By David Flanagan ISBN:0-596-00048-0 (Also by
> David Flanagan: JavaScript Pocket Reference, 2nd Edition.
> ISBN 0-596-00411-7 for language and API reference alone).
> </draft>[/color]

"One of the best books" instead of "The best book" perhaps? It precludes
a new book coming out in a month that is better, and best/better is
subjective, is it not?

--
Randy

Dr John Stockton
Guest
 
Posts: n/a
#28: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <I_mdnV1p5MXhd5zdRVn-hw@comcast.com>, seen in
news:comp.lang.javascript, Randy Webb <hikksnotathome@aol.com> posted at
Sun, 11 Jan 2004 19:28:47 :-[color=blue]
>Dr John Stockton wrote:[/color]
[color=blue][color=green]
>> It is not harmless if the coder put a false statement in a Div expecting
>> it to be over-written.[/color]
>
>If a coder puts code in that he expects to be over-written, then he
>almost deserves what he gets for not realizing that it won't be
>over-written.
>
>How would you over-write it in non-js browsers?
>
>To put a false statement in expecting it to be over-written is a fallacy
>on the web-authors part.[/color]

"False" needed more qualification; I meant one which would not
necessarily remain appropriate after user interaction, and a blank can
be an example of this. "Error messages should appear here", for
example.



[color=blue][color=green]
>> Perhaps the example in the FAQ should have HTML resembling
>> <div ID=XXX>This should not remain here.</div>.
>>[/color]
>
>Why? The idea is not to depend on javascript, but to use it to
>complement the page. So why would you want to start with text that
>shouldn't remain in the absence of client-side scripting?[/color]

No; that is but one idea.

When javascript is executed automatically during or after the loading of
a page, then the display needs to be valid whether or not client-side
scripting is operating; and as far as can be managed valid if it is
partly operating. That would be the case for a typical "advertising"
page, in which the script provides mere decoration.

But when the purpose of a page, or part of a page, is to do some sort of
calculation, then the user should as far as possible not be left in
doubt when the aim of the coder has not been achieved. If scripting is
not working, it cannot give such an indication; but, if it is, it can
remove one.

Then, of course, the words "This should not remain here." do not specify
when they should cease to remain. If it is not appropriate for them to
ever appear on the page, then the coder should remove them by editing,
rather than by programming an over-write.

The important thing is that the example should indicate the possibility
of putting initial material in the Div; one who needs to use code from a
javascript FAQ certainly does not know everything about scripting, and
should not be presumed to know everything about HTML; he may never have
used div tags, and may be unaware that they are allowed content.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
some Astro stuff via astro.htm, gravity0.htm; quotes.htm; pascal.htm; &c, &c.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Richard Cornford
Guest
 
Posts: n/a
#29: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Randy Webb" <hikksnotathome@aol.com> wrote in message
news:GY2dnaRoo6k9e5_dRVn-hQ@comcast.com...
<snip>[color=blue][color=green]
>>So something like:-
>><draft>
>>3.1 What books cover javascript?
>> The best book currently available is: javascript: The
>> Definitive Guide, 4th Edition By David Flanagan
>> ISBN:0-596-00048-0 (Also by David Flanagan:
>> JavaScript Pocket Reference, 2nd Edition.
>> ISBN 0-596-00411-7 for language and API reference alone).
>></draft>[/color]
>
>"One of the best books" instead of "The best book" perhaps? It
>precludes a new book coming out in a month that is better,
>and best/better is subjective, is it not?[/color]

"Best" is subjective, but it is not the opinion of just one person. The
proposal for the inclusion of The Definitive Guide received some fairly
heavyweight support and nobody had a word to say against it. While no
other books were even proposed as suitable at the time.

That makes me think that "the best book" may be better than "one of the
best books", because there do no appear to be any other contenders at
present. (which is what "one of" would imply). Because that statement
is followed with "currently available", and assuming that readers have
enough sense to interpret that as referring to the time of writing, that
seems to admit the possibility of new books becoming contenders for the
title.

Though it would be nice to have other books to list and so be able to
use "The best books currently available". A large part of the problem is
that as books move away from language and browser (or other) API
descriptions and more towards trying to instruct people in the scripting
of browsers the more they tent to promote techniques that are either
objectively wrong or subjectively objectionable. It probably wouldn't
take more than one regular pointing out grounds for objecting to (the
code style/techniques used in) a book to keep it out of the FAQ.

Richard.


Dr John Stockton
Guest
 
Posts: n/a
#30: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <ggXjOBBkLGAAFw8G@jgharris.demon.co.uk>, seen in
news:comp.lang.javascript, John G Harris <john@nospam.demon.co.uk>
posted at Sat, 10 Jan 2004 20:39:00 :-[color=blue]
>In article <8LHDu3KIhw$$Ewb4@merlyn.demon.co.uk>, Dr John Stockton
><spam@merlyn.demon.co.uk> writes[color=green]
>>JRS: In article <btl7ak$4on$1$8300dec7@news.demon.co.uk>, seen in
>>news:comp.lang.javascript, Richard Cornford
>><Richard@litotes.demon.co.uk> posted at Fri, 9 Jan 2004 03:31:32 :-[/color]
> <snip>[color=green][color=darkred]
>>>GMT or UTC (strictly)?[/color]
>>
>>Strictly, I believe, UT. But that looks like a misprint for UTC.[/color]
> <snip>
>
>Strictly, none of these. You will find[/color]

Statement not as immediately accurate as you evidently expected, as the
server appeared to be down when first I looked.
[color=blue]
> a refreshingly clear, as well as
>accurate, account of calendar and time systems at
>
> <URL:http://www.npl.co.uk/time/time_scales.html>[/color]

The page is sound, but it is less detailed than others that my Web site
links to.
[color=blue]
>Javascript date objects use a rule for allocating each second to a
>particular minute/hour/day/month/year that hasn't got an official name.
>Approximate local time is as good a description as any.[/color]

Well, no, because it is far too long. We do need to use a single word
or acronym. Standards bodies do not seem to have defined a short name
for a time scale 60*60*24*365.2425 but with the length of the unit
drifting about and the reading subject to sudden corrections in rate or
value, but without Summer Time.
ISTM that our requirements are for a name that implies no Summer Time,
implies no Leap Seconds, and is generally recognisable.


--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Dr John Stockton
Guest
 
Posts: n/a
#31: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <f62097a4.0401120912.365f7c41@posting.google.com >, seen
in news:comp.lang.javascript, Steve Allen <sla@ucolick.org> posted at
Mon, 12 Jan 2004 09:12:28 :-[color=blue]
>Dr John Stockton <spam@merlyn.demon.co.uk> wrote in message news:<NAW$8PAy+ZAAFw
>rH@merlyn.demon.co.uk>...[color=green]
>> JRS: In article <btqcpe$qmq$1$8300dec7@news.demon.co.uk>, seen in
>> news:comp.lang.javascript, Richard Cornford
>> <Richard@litotes.demon.co.uk> posted at Sun, 11 Jan 2004 02:35:15 :-[color=darkred]
>> >"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
>> >news:8LHDu3KIhw$$Ewb4@merlyn.demon.co.uk...[/color][/color]
>[color=green][color=darkred]
>> > Time is measured in ECMAScript in milliseconds since 01 January,
>> > 1970 UTC.[/color][/color]
>
>Regarding the meaning of the date 1970-01-01T00:00:00 I recommend
>reading
>http://www.ucolick.org/~sla/leapsecs...bib.html#POSIX
>and down a bit further at
>http://www.ucolick.org/~sla/leapsecs...tml#POSIXepoch[/color]

For true definitions, I prefer to rely on BIPM and national standards
laboratories. POSIX ought to match these, but might be in error.

[color=blue][color=green][color=darkred]
>> > Leap seconds are ignored. It is assumed that there are
>> > exactly 86,400,000 milliseconds per day. ...[/color]
>>
>> That's certainly a wrong thing to put, of course, to say "per
>> UTC day" would at least be consistent.[/color][/color]

"consistent" does not mean "right" or "appropriate". The day has not
yet been indicated as without Summer Time changes; that is why 864e5
ms/d alone is unsatisfactory.

[color=blue]
>No, all forms of day other than UTC days always have exactly 86400
>seconds. It is *only* a UTC day which can have other than 86401 (or
>86399) seconds.[/color]

Misleading. The civil day can have 23 or 25 hours, and it is the civil
day which ordinary people deal with [GMT has had a day of 12 hours, and
HM ships had ones of 36 hours once each (that's George III's Majesty)].
The superfluous other should be obvious, though.

Their meaning is clear enough; but their wording is not all that it
could be.
[color=blue]
> This is why I assert that most system clocks are
>actually counting mean solar seconds, and not SI seconds.[/color]

To within the accuracy of almost any computer clock, there's no
difference between the lengths of those; the important thing is whether
the minute can occasionally be divided into 59 or 61. Most time
standards will approximate mss as opposed to SIs, though IIRC GPS is SI-
based.


BTW, to judge from Summer Time changes, as given in English, the EU
operates on GMT, not UTC.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Richard Cornford
Guest
 
Posts: n/a
#32: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
news:NAW$8PAy+ZAAFwrH@merlyn.demon.co.uk...
<snip>[color=blue][color=green]
>>Unfortunately it is not as simple as that. ...[/color][/color]
<snip>

A recent thread with the subject "Changing text between <div>'s"
discussed the task of testing for a browser's dynamic support (rather
than, say, read only) for innerHTML, and was also one of the threads
discussing the suitability of the 4.15 code. Taking the tests discussed
there and adding a - typeof el.innerHTML == 'string' - test, which I was
surprised was not raised in that thread, might result in code like:-

/*Emulate getElementById on document.all only browsers. But only if
IDs are unique to the page and do not coincide with NAME attributes
on other elements.*/
if((!document.getElementById) && document.all){
document.getElementById = function(id){return document.all[id];};
}

if(document.getElementById){
DynWrite= function(id, S){
var testH, newH, inH, testID, el = document.getElementById(id);
if((el)&&(typeof el.innerHTML == 'string')){
testID = "tst";
while(document.getElementById(testID)){
testID += testID;
}
inH = el.innerHTML;
/*The following mixed case HTML string is not an error*/
newH = inH+"<sTrOnG Id='"+testID+"' >test<\/StRoNg >";
el.innerHTML = newH; //Assumes synchronous update of DOM.
testH = el.innerHTML;
if((testH != newH)&& //Apparently normalised or unchanged.
(testH != inH)&& //Not unchanged (read only).
(document.getElementById(testID))){//Element found in DOM.
DynWrite = new Function("id", "S",
"document.getElementById(id).innerHTML=S; return true");
}else{
DynWrite = new Function("return false;");
}
}else{
DynWrite = new Function("return false;");
}
return DynWrite(id, S);
}
}else{
DynWrite = new Function("return false;");
}

Which should result in more unsupporting browsers returning false from
calls to DynWrite, but it could do with more testing. It is also about 3
times the size of the existing code and is still relying of the
assumption that assigning a string to the innerHTML property will result
in a synchronous update of the DOM, which might not be true for all
innerHTML browsers.

<snip>[color=blue][color=green]
>>I suspect that the copt'n'paste merchants actively
>>don't want to understand what they are doing
>>(witness George Hester) and are likely to[/color]
> ^^^^^^^^^^^^^
>No; until I see reason to believe that his style has changed to conform
>with Usenet standards, I'll not witness that; but it's easy to believe.[/color]

Nothing has changed (in 2+ years) including his knowledge of JavaScript,
hence my comment.

Richard.


Dr John Stockton
Guest
 
Posts: n/a
#33: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <btuvs0$l8g$1$830fa7a5@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Richard@litotes.demon.co.uk> posted at Mon, 12 Jan 2004 20:25:34 :-
[color=blue][color=green]
>>"One of the best books" instead of "The best book" perhaps? It
>>precludes a new book coming out in a month that is better,
>>and best/better is subjective, is it not?[/color]
>
>"Best" is subjective, but it is not the opinion of just one person. The
>proposal for the inclusion of The Definitive Guide received some fairly
>heavyweight support and nobody had a word to say against it. While no
>other books were even proposed as suitable at the time.[/color]

If "the best" is used, then that needs to be qualified by an attached
date, or reviewed daily, because a new, better book may be published.

Most readers of the group will never have seen, and will be unable to
evaluate, books written in French, German, Russian, ... - yet it is
quite possible that one of these may be as good as or better than
Flanagan's.

Where a document cites a number of books, one or more, in a general
manner, then it is implicit that, in the opinion of those responsible
for the document (the editors and the newsgroup regulars) that they are
good books; that is all that needs to be said.

We should remember, though, that an outstanding and compendious book may
not be the best for all classes of use. A professional programmer might
choose to order both Flanagans, since small books are easier to refer
to. It is likely that a non-programmer might be better suited by a
different type of book.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Dr John Stockton
Guest
 
Posts: n/a
#34: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <btvi86$2m3$1$830fa7b3@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Richard@litotes.demon.co.uk> posted at Tue, 13 Jan 2004 01:39:18 :-
[color=blue]
>A recent thread with the subject "Changing text between <div>'s"
>discussed the task of testing for a browser's dynamic support (rather
>than, say, read only) for innerHTML, and was also one of the threads
>discussing the suitability of the 4.15 code. Taking the tests discussed
>there and adding a - typeof el.innerHTML == 'string' - test, which I was
>surprised was not raised in that thread, might result in code like:-
>
>/*Emulate getElementById on document.all only browsers. But only if[/color]
??? change above to ?? -> Requires that[color=blue]
>IDs are unique to the page and do not coincide with NAME attributes
>on other elements.*/
>if((!document.getElementById) && document.all){
> document.getElementById = function(id){return document.all[id];};
>}
>
>if(document.getElementById){
> DynWrite= function(id, S){
> var testH, newH, inH, testID, el = document.getElementById(id);
> if((el)&&(typeof el.innerHTML == 'string')){
> testID = "tst";
> while(document.getElementById(testID)){[/color]
// generate unique ID // add that ??
[color=blue]
> testID += testID;
> }
> inH = el.innerHTML;
> /*The following mixed case HTML string is not an error*/
> newH = inH+"<sTrOnG Id='"+testID+"' >test<\/StRoNg >";
> el.innerHTML = newH; //Assumes synchronous update of DOM.
> testH = el.innerHTML;
> if((testH != newH)&& //Apparently normalised or unchanged.
> (testH != inH)&& //Not unchanged (read only).
> (document.getElementById(testID))){//Element found in DOM.
> DynWrite = new Function("id", "S",
> "document.getElementById(id).innerHTML=S; return true");
> }else{
> DynWrite = new Function("return false;");
> }
> }else{
> DynWrite = new Function("return false;");
> }
> return DynWrite(id, S);[/color]
// ??!!??!!?? ?? ??
[color=blue]
> }
>}else{
> DynWrite = new Function("return false;");
>}
>
>Which should result in more unsupporting browsers returning false from
>calls to DynWrite, but it could do with more testing.[/color]


I don't follow its structure entirely.

The code should only be executed once per page, and the time taken
should be unimportant; hence, optimisation should be for legibility.
For that, it might be better to define
DynWrite = new Function("return false;")
in the first instance, and redefine it later if possible; that would
obviate the else parts.

Alternatively, one might make the major part explicitly set a boolean
ThatCanBeDone, then
DynWrite = new Function( "id", "S",
ThatCanBeDone
? "document.getElementById(id).innerHTML=S; return true"
: "return false" )

(I don't know whether that's right, but MSIE4 accepts it.)

[color=blue]
> It is also about 3
>times the size of the existing code and is still relying of the
>assumption that assigning a string to the innerHTML property will result
>in a synchronous update of the DOM, which might not be true for all
>innerHTML browsers.[/color]

Which is why I favour something which suggests a visual test.
Suggestions are of course not mandatory, but they do mean that a
possibility should not be overlooked.

P.S. Mail to jrs@ bounces reliably, unread. Mail to other currently-
specified addresses does not.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
John G Harris
Guest
 
Posts: n/a
#35: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


In article <VWZZJ4BM7vAAFwpA@merlyn.demon.co.uk>, Dr John Stockton
<spam@merlyn.demon.co.uk> writes
<snip>[color=blue][color=green]
>>Strictly, none of these. You will find[/color]
>
>Statement not as immediately accurate as you evidently expected, as the
>server appeared to be down when first I looked.[/color]

Good. This means that your taxes are not being wasted on a quadruple
redundancy web server with hot updates.
[color=blue][color=green]
>> a refreshingly clear, as well as
>>accurate, account of calendar and time systems at
>>
>> <URL:http://www.npl.co.uk/time/time_scales.html>[/color]
>
>The page is sound, but it is less detailed than others that my Web site
>links to.[/color]

You obviously didn't notice that I was commenting on an article in this
thread, not on the FAQ.

The page is sound, but people should note that it's aimed at non-experts
and is very much a statement of general principles.
[color=blue][color=green]
>>Javascript date objects use a rule for allocating each second to a
>>particular minute/hour/day/month/year that hasn't got an official name.
>>Approximate local time is as good a description as any.[/color]
>
>Well, no, because it is far too long. We do need to use a single word
>or acronym. Standards bodies do not seem to have defined a short name[/color]

Yes they have. There is an international standard for ECMAScript and its
Date objects, so "ECMAScript Date time" is what you are looking for.
("ECMAScript" can be left out if the context makes it obvious).
[color=blue]
>for a time scale 60*60*24*365.2425 but with the length of the unit
>drifting about[/color]

A Date object holds an integral number. What the number means is
entirely up to the user. Whether it represents equally spaced time
intervals or variable ones is a user decision.
[color=blue]
>and the reading subject to sudden corrections in rate or
>value,[/color]

But only if your application is sampling the computer clock. (A Date
object doesn't change just because time is passing).
[color=blue]
> but without Summer Time.
>ISTM that our requirements are for a name that implies no Summer Time,
>implies no Leap Seconds, and is generally recognisable.[/color]

It's unlikely to be generally recognisable.

John
--
John Harris
Richard Cornford
Guest
 
Posts: n/a
#36: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
news:jm8UVZAaV$AAFwtT@merlyn.demon.co.uk...
<snip>[color=blue]
>The code should only be executed once per page,[/color]

Yes.
[color=blue]
>and the time taken should be unimportant;[/color]

True.
[color=blue]
>hence, optimisation should be for legibility.
>For that, it might be better to define
> DynWrite = new Function("return false;")
>in the first instance, and redefine it later if possible;
>that would obviate the else parts.
>
>Alternatively, one might make the major part explicitly
>set a boolean
>ThatCanBeDone, then
> DynWrite = new Function( "id", "S",
> ThatCanBeDone
> ? "document.getElementById(id).innerHTML=S; return true"
> : "return false" )
>
>(I don't know whether that's right, but MSIE4 accepts it.)[/color]

I think I spent too much time incorporating the tests into the existing
functions and should have taken a step back and looked at the bigger
picture. There certainly is a simpler structure for the function. In
fact there is no real need to configure DynWrite as the page loads and
create a "return false;" function at that point.

A simplified revision (bloated by comprehensive comments) would be:-

function DynWrite(id, S){
var testH, newH, inH, testID;
/* Set the default value for the body text of the function that
will be created to replace this function as the DynWrite
function.
*/
var funcBody = "return false;"
/* Ensure that getElementById is available (or emulated) on this
browser prior to calling it.
*/
var el = (document.getElementById)?document.getElementById( id):null;
/* Ensure that the referenced element has been successfully
retrieved and test to verify that its innerHTML property is
a string (as opposed to being undefined).
*/
if((el)&&(typeof el.innerHTML == 'string')){
/* Arbitrary string to use as an ID for an element that
should be created as a result of writing to the innerHTML
value (The string itself and the result of concatenating it
to itself (repeatedly) should follow the rules for valid
HTML ID attributes).
*/
testID = "tst";
/* Ensure that the test ID is not in use on the page by
modifying it until an element cannot be retrieved using it.
*/
while(document.getElementById(testID)){
testID += testID;
}
inH = el.innerHTML; //Read the original innerHTML value.
/* The following mixed case HTML string is _not_ an error.
*/
newH = inH+"<sTrOnG Id='"+testID+"' >test<\/StRoNg >";
el.innerHTML = newH; //Assumes synchronous update of DOM.
testH = el.innerHTML; //Read innerHTML back for examination.
if((testH != newH)&& //Apparently normalised or unchanged.
(testH != inH)&& //Not unchanged (Not read-only).
(document.getElementById(testID))){ //Element found in DOM.
/* TESTS PASSED! Replace the default function body string
with code that will set the innerHTML property of the
element and return true, based on the assumption that
the assignment will be successful because this test was
sucessful.
*/
funcBody =
"document.getElementById(id).innerHTML=S; return true";
}
}
/* Replace the DynWrite function with one determined by the results
of the tests.
*/
DynWrite = new Function("id", "S", funcBody);
/* Call the newly created DynWrite function and return its return
value as the return value for this function call.
*/
return DynWrite(id, S);
}

(It is actually only 20 lines of code)

It addresses Jim's back-compatibility concerns surrounding support for
function expressions as it now uses a single function declaration (so no
support problems there) and the call to the Function constructor that it
uses is suited to the situation as the function body is assigned at
run-time.

On the other hand I am still reluctant to use that in the place of the
earlier version, partly because it would represent a considerable
expansion of the FAQ entry (and thus the size of the FAQ postings to the
group) and partly because it would warrant additional explanation and
discussion.

Reading section 1: <quote>meta-FAQ as it mainly provides URLs to further
information </quote> it occurred to me that an obvious compromise would
be to provide additional information at a public URL. Possibly in the
form of a page of additional notes on any FAQ entries that were seen as
requiring it, allowing an expansion in the detail provided without the
consequent expansion in the FAQ as posted.

It would make most sense if such a page was on Jim's server with the FAQ
but I have put together an example of notes on 4.15 (probably incomplete
at present) for consideration:-

<URL: http://www.litotes.demon.co.uk/js_in...FAQ_Notes.html >

<snip>[color=blue]
>Which is why I favour something which suggests a visual test.
>Suggestions are of course not mandatory, but they do mean
>that a possibility should not be overlooked.[/color]

I can see how that suites your application of DynWrite, and there is an
inverse relationship between a user being able to read content within an
element and the success of a call to DynWrite that attempted to replace
it (that is, if successfully replaced the previous content cannot be
read).

Personally I would tackle the problem that you are using DynWrite to
address with a different strategy (probably using a pre-processor to
generate a static HTML page from the date whenever the data was changed)
and I don't really like the idea of telling the user that their browser
is not up to the task of showing the content of a page as there probably
won't be much that they can (or are willing) to do about that. But then
I don't really like using scripts to insert content that is necessary as
part of the page.

But opinions (and circumstances) differ. A short discussion of the
issues might make for an addition note on 4.15 (but would be far too
much for inclusion in the FAQ).
[color=blue]
>P.S. Mail to jrs@ bounces reliably, unread. Mail to other
>currently specified addresses does not.[/color]

I figured, but it wasn't that important. :)

Richard.


Dr John Stockton
Guest
 
Posts: n/a
#37: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <RQLvCCDTaGBAFwRR@jgharris.demon.co.uk>, seen in
news:comp.lang.javascript, John G Harris <john@nospam.demon.co.uk>
posted at Tue, 13 Jan 2004 21:43:47 :-[color=blue]
>In article <VWZZJ4BM7vAAFwpA@merlyn.demon.co.uk>, Dr John Stockton
><spam@merlyn.demon.co.uk> writes[/color]

[color=blue][color=green][color=darkred]
>>>Javascript date objects use a rule for allocating each second to a
>>>particular minute/hour/day/month/year that hasn't got an official name.
>>>Approximate local time is as good a description as any.[/color]
>>
>>Well, no, because it is far too long. We do need to use a single word
>>or acronym. Standards bodies do not seem to have defined a short name[/color]
>
>Yes they have. There is an international standard for ECMAScript and its
>Date objects, so "ECMAScript Date time" is what you are looking for.
>("ECMAScript" can be left out if the context makes it obvious).[/color]

Still too long; and does not make the distinction between a scale that
has leap seconds or has steps in spring and autumn or is location-
dependent, and one which does not.

[color=blue][color=green]
>>ISTM that our requirements are for a name that implies no Summer Time,
>>implies no Leap Seconds, and is generally recognisable.[/color]
>
>It's unlikely to be generally recognisable.[/color]

"GMT" is generally recognisable, and has all the required properties
(including the omitted non-locality). The other terms which may be
needed by non-chronometrists are UTC, for a scale based in the SI second
with leap seconds (not supported in javascript); and local civil time,
which is what the clock-in-the-street ought to be showing.

For the last, the acronym LCT has been used; few can be expected to
recognise it in a document until after it has been explained, but after
that it should be memorable enough.




For an alternative to the suggested
"Qn : Why does date ( differencing | incrementing ) go wrong?
Ans : Date is basically held as GMT, ..."
maybe
"...
Ans: Date is held as a number of milliseconds, ..."

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Dr John Stockton
Guest
 
Posts: n/a
#38: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <bu2kce$8cg$1$8300dec7@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Richard@litotes.demon.co.uk> posted at Wed, 14 Jan 2004 05:34:05 :-

[color=blue]
>A simplified revision (bloated by comprehensive comments) would be:-[/color]

Possibly add a more DynWrite-global comment, e.g.
function DynWrite(id, S){ // Generates a successor when first called!
would help.

It is common to put comment after its target, because of use of // - it
took me a few moments to see that your /* ... */ comment precedes its
target (which is better). I suggest that changing the final full stop
in each such comment to dash or colon or colon-dash would help.

[color=blue]
> ...[/color]
[color=blue]
> /* Ensure that getElementById is available (or emulated) on this
> browser prior to calling it.
> */[/color]
[color=blue]
> ...[/color]
[color=blue]
> testID = "tst";
> /* Ensure that the test ID is not in use on the page by
> modifying it until an element cannot be retrieved using it.
> */[/color]

As a trivial optimisation, ISTM that "tSt" is even less likely to pre-
exist.
[color=blue]
> ...[/color]
[color=blue]
>On the other hand I am still reluctant to use that in the place of the
>earlier version, partly because it would represent a considerable
>expansion of the FAQ entry (and thus the size of the FAQ postings to the
>group) and partly because it would warrant additional explanation and
>discussion.[/color]

Since you've done the work, the result should at least be linked from
the FAQ on a WWW page; looking ahead, you seem to agree.
[color=blue]
> ...[/color]
[color=blue]
><URL: http://www.litotes.demon.co.uk/js_in...FAQ_Notes.html >[/color]
[color=blue]
> ...[/color]
[color=blue]
>Personally I would tackle the problem that you are using DynWrite to
>address with a different strategy (probably using a pre-processor to
>generate a static HTML page from the date whenever the data was changed)[/color]

That could be done, by uploading every night, in a page like my
miscdate.htm. After describing JD in HTML, javascript there writes the
current value. But most pages are responding to buttons and processing
user-entered data.

My zel-1882.htm is an example of a page where the bulk uses no script at
all, but the final section is a javascript date calculator,
demonstrating what precedes it. And holidays.htm is almost useless
without javascript, though that could be pre-processed about once a
year.

[color=blue]
>and I don't really like the idea of telling the user that their browser
>is not up to the task of showing the content of a page as there probably
>won't be much that they can (or are willing) to do about that. But then
>I don't really like using scripts to insert content that is necessary as
>part of the page.[/color]

Think of my pages as being in part mere vehicles carrying and describing
the vital code; or not as HTML with extras but as programs in their own
right. The reader with an unsuitable browser *will* know that something
is wrong; he should know what. If someone produces a page which fails
on my system, I give up; but if it explains that a function cannot be
provided on the particular browser, I may continue in the Library
tomorrow.
[color=blue]
>But opinions (and circumstances) differ. A short discussion of the
>issues might make for an addition note on 4.15 (but would be far too
>much for inclusion in the FAQ).[/color]


As the function itself, while operationally equivalent, is so different
from the existing FAQ version, ISTM that a new name might save confusion
in subsequent discussion - DynWrite2? WriteDyn?

An example such as
HTML: <div ID=Idfy>old HTML</div>
Script: if (!DynWrite("Idfy", "new HTML") { alert("No good") }
DynWrite("Idfy", "more HTML")
would help; here, while the alert *could* be copied, its purpose here is
as a dummy to be replaced by something more appropriate when the IF form
is used.

In a FAQ, where a function has a return value, ISTM that there should be
an example using it.



There seems to be a problem, though, it does not work in my MSIE4,
returning false. Var el is null. I see, /* Ensure ... undefined). */
is not a comment, it is an ORDER. Suggest STRESSING it - "YOU MUST
ensure ..." and using "This ensures ..." elsewhere.

Adding :

if((!document.getElementById) && document.all){
document.getElementById = function(id){return document.all[id];};
}

it works in my MSIE4, provided that I don't call DynWrite while the body
is loading (that gives script error 8000000a); but it's OK invoked by
<body onload=""> or by a button.

Good.


I see a slight imperfection; in the first call, it creates the "null"
DynWrite if the ID is not found; if the ID is later not found, a browser
error is caused.
[color=blue]
> "document.getElementById(id).innerHTML=S; return true";[/color]

"var T = document.getElementById(id);" +
" if (T!=U) { T.innerHTML=S; return true } " +
" else {alert('no '+id) ; return false; }";

with var U being global (MSIE4 seems not to have defined undefined) ???


However, mis-addressing is an error that should be found before the page
is published, and a warning that there's a difference between first and
subsequent, or a change to make the first match subsequent, should do.


Since id is not an uncommon string, there'd be slight advantage in using
something other than id as the parameter - IDty ?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Richard Cornford
Guest
 
Posts: n/a
#39: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
news:imkUVTE$WuBAFwVT@merlyn.demon.co.uk...
<sniped comments on minor changes>

I have either made modifications in accordance with, or had already
covered the points you raised above in the page referenced below.
[color=blue]
>Since you've done the work, the result should at least be
>linked from the FAQ on a WWW page; looking ahead, you seem
>to agree.[/color]

Yes, there is no point in writing it and then not making it publicly
available. Updated:-

<URL:
http://www.litotes.demon.co.uk/js_in....html#AltDynWr >

<snip>[color=blue]
>As the function itself, while operationally equivalent, is so
>different from the existing FAQ version, ISTM that a new name
>might save confusion in subsequent discussion - DynWrite2? WriteDyn?[/color]

I have been describing the function as an alternative DynWrite but maybe
it does need a different name.

<snip>[color=blue]
>In a FAQ, where a function has a return value, ISTM that there
>should be an example using it.[/color]

I will bare that in mind.
[color=blue]
>There seems to be a problem, though, it does not work in my MSIE4,
>returning false. Var el is null. I see, /* Ensure ... undefined). */
>is not a comment, it is an ORDER. Suggest STRESSING it - "YOU MUST
>ensure ..." and using "This ensures ..." elsewhere.[/color]

That comment was not intended to be an order, but clearly I do need to
stress more the necessity of setting up the element retrieval method
before using DynWrite. (And make the comments less like orders).
[color=blue]
>Adding :
>
> if((!document.getElementById) && document.all){
> document.getElementById = function(id){return document.all[id];};
> }
>
>it works in my MSIE4, provided that I don't call DynWrite while
>the body is loading (that gives script error 8000000a); but it's
>OK invoked by <body onload=""> or by a button.
>
> Good.[/color]

OK. So did Jim's original DynWrite error if called before onload on IE 4
or is it something that I have introduced? I can't think what it would
be, unless it is the - typeof el.innerHTML - test or the act or reading
the innerHTML prior to the document being fully set-up, as nothing else
is really different.
[color=blue]
>I see a slight imperfection; in the first call, it creates the "null"
>DynWrite if the ID is not found; if the ID is later not found, a[/color]
browser[color=blue]
>error is caused.
>[color=green]
>> "document.getElementById(id).innerHTML=S; return true";[/color]
>
> "var T = document.getElementById(id);" +
> " if (T!=U) { T.innerHTML=S; return true } " +
> " else {alert('no '+id) ; return false; }";
>
>with var U being global[/color]

document.getelementById is supposed to return null when it cannot find
an element with the corresponding ID, Randy's emulation returns
undefined but in most cases a type-converting test - if(T){
/*exists*/ } - would be suitably discriminating. I had thought of this
and proposed:-

"var el=document.getElementById(id);"+
"if(el){el.innerHTML=S;}return !!el;"

(MSIE4 seems not to have defined undefined) ???

That informative "undefined is undefined" error that IE 4 produces. :)

An alternative along the lines of Randy's getElementById emulation is:-

window.undefined = window.undefined;

- or -

this.undefined = this.undefined; //executed in a global context.

- which emulates the - undefined - keyword on browsers that do not
implement it like IE 4 (if executed prior to any use of - undefined). It
is harmless in an environment that implements - undefined.
[color=blue]
>However, mis-addressing is an error that should be found before
>the page is published, and a warning that there's a difference
>between first and subsequent, or a change to make the first
>match subsequent, should do.[/color]
<snip>

Yes, for development you want to catch those errors and fix the
HTML/JavaScript. For deployed code the element reference testing version
might cover the unexpected actions of content inserting proxies (not
that they should be expected to be messing around with ID attributes).

Richard.


Richard Cornford
Guest
 
Posts: n/a
#40: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Richard Cornford" <Richard@litotes.demon.co.uk> wrote in message
news:bu83be$aea$1$8300dec7@news.demon.co.uk...
<snip>[color=blue]
>document.getelementById is supposed to return null when it cannot
>find an element with the corresponding ID, Randy's emulation
>returns undefined but in most cases a type-converting test -
>if(T){ /*exists*/ } - would be suitably discriminating. I had
>thought of this and proposed:-
>
> "var el=document.getElementById(id);"+
> "if(el){el.innerHTML=S;}return !!el;"[/color]
<snip>

On the other hand it is also possible to create a better getElementById
emulation that always returns an element or null (as opposed to
undefined). So it would have to implement a series of test on the object
retrieved from the document.all collection, but that would remove the
requirement that IDs be unique (except that valid HTML requires that)
and do not correspond with the NAME attribute of other elements:-

/* Emulate getElementById on document.all only browsers. */
if((!document.getElementById) && document.all){
document.getElementById = function(id){
var tempEl = null, el = document.all[id];
if(el){ //document.all returned something.
if((!el.id)||(el.id != id)){
/* Either this is a collection or the only element
available under the property name provided as the
- id - parameter is a named element:
*/
if(el.length){ //assume it is a collection.
/* But it might be an element with a NAME
corresponding with the id parameter that has
collection-like behaviour such as a form or a
select element so proceed with caution:
*/
for(var c = 0;c < el.length;c++){
if((el[c].id)&&(el[c].id == id)){
/* Set tempEl to the first match and
break out of the - for - loop:
*/
tempEl = el[c];
break;
}
}
/* el will be set to null if the loop did not
find an element with the corresponding ID
because the default null value of tempEl
will not have changed:
*/
el = tempEl;
}else{ //only a named element is available for id.
/* getElementById should not return named elements
only an IDed element so set el to null:
*/
el = null;
}
} //else we have our element (the ID matches).
}else{ //el is undefined so make it null;
el = null;
}
/* The returned value will be the first element confirmed as
having the corresponding ID or it will be null:
*/
return el;
};
}


That getElementById emulation (assuming my logic is sound and I haven't
missed anything) is closer to the W3C getElementById function than the
implementation in IE 5.0+ (which will erroneously return elements with
corresponding NAME attributes).

Richard.


Dr John Stockton
Guest
 
Posts: n/a
#41: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <bu83be$aea$1$8300dec7@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Richard@litotes.demon.co.uk> posted at Fri, 16 Jan 2004 07:20:13 :-[color=blue]
>"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
>news:imkUVTE$WuBAFwVT@merlyn.demon.co.uk...
><sniped comments on minor changes>[/color]
[color=blue][color=green]
>>it works in my MSIE4, provided that I don't call DynWrite while
>>the body is loading (that gives script error 8000000a); but it's
>>OK invoked by <body onload=""> or by a button.
>>
>> Good.[/color]
>
>OK. So did Jim's original DynWrite error if called before onload on IE 4
>or is it something that I have introduced?[/color]

Jim's does the same. I tend to think that errors 8000???? are errors
of the browser rather than errors of the code; I usually manage to fix
them by doing things differently rather than by correcting a definite
coding error. I see no need to call it before onload; the problem IMHO
warrants no more than a "Don't do that, it sometimes fails" in the Web
document.
[color=blue]
>I can't think what it would
>be, unless it is the - typeof el.innerHTML - test or the act or reading
>the innerHTML prior to the document being fully set-up, as nothing else
>is really different.[/color]

Testing Jim's, it is the act. Changing Jim's DynWrite body to

"var Q = GetRef(id) ; alert(8) ; Q.innerHTML=S; alert(9) ; return true"

with a DynWrite call both in the script proper and as onload gives
8, error, *no* 9 & page unchanged, 8, pagechange, 9. So it is, in
Jim's, the act of writing the innerHTML. Similar testing of yours
shows that the read operates correctly but your write of NewH gives
error.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Dr John Stockton
Guest
 
Posts: n/a
#42: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


JRS: In article <bu8oln$pbm$1$8300dec7@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Richard@litotes.demon.co.uk> posted at Fri, 16 Jan 2004 13:24:06 :-[color=blue]
>
>That getElementById emulation (assuming my logic is sound and I haven't
>missed anything) is closer to the W3C getElementById function than the
>implementation in IE 5.0+ (which will erroneously return elements with
>corresponding NAME attributes).[/color]


I think it would be acceptable to stipulate that the first argument of
DynWrite must be unique among the whole set of IDs and NAMEs ( on the
page | in the scope ), although that should not be the best way to say
it.

My holidays.htm could have needed the same ID in different scopes; but
the actual ID is of the nature "XXX" + J++ and hence not re-used
either in visually different forms or in re-draws of the same one. Just
don't click it more than 2^53 times per page-reload, though.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Richard Cornford
Guest
 
Posts: n/a
#43: Jul 20 '05

re: FAQ update (roundup of pending requests - for comment)


"Dr John Stockton" <spam@merlyn.demon.co.uk> wrote in message
news:qbgGaKGi4DCAFwfq@merlyn.demon.co.uk...
<snip>[color=blue]
>... . I tend to think that errors 8000???? are errors
>of the browser rather than errors of the code; ...[/color]
<snip>

That would have been my guess.
[color=blue]
>I see no need to call it before onload;[/color]

Neither do I. In most (HTML) circumstances document.write is an
effective way of inserting HTML into a document as it loads (obviously
subject to JS support).
[color=blue]
>the problem IMHO warrants no more than a "Don't do that,
>it sometimes fails" in the Web document.[/color]
<snip>

OK, and thanks for confirming that the IE 4 problem relates directly to
the assignment to the innerHTML property (and wasn't something that I
had added).

Richard.


Closed Thread