Re: With YYYYMMDD Trying to change MM to August
- From: Thomas 'PointedEars' Lahn <PointedEars@xxxxxx>
- Date: Fri, 22 Feb 2008 21:14:58 +0100
RobG wrote:
Alan Gresley wrote:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Data Table</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml;
charset=utf-8" />
If you really are serving this as XHTML, then you clearly don't care
about users of IE or of browsers more than a few years old.
And if he is really serving this as advertised, the XML parser that is used
then will not care about the advertisement. At this point, the parse tree
has been built because the markup is well-formed, or there is no document.
However, content provided in an encoding that does not match the HTTP header
or XML declaration value, or that which is determined by reading the BOM,
can not be well-formed.
<script type="text/javascript">
So it would be wise to use a correct type:
type="application/x-javascript"
There is nothing correct about this. You were (not) looking for
"application/javascript", see http://PointedEars.de/scripts/test/mime-types
(updated).
function getElements()
All script within the script element should be enclosed in #PCDATA
quotes:
<![CDATA[
<URL: http://www.w3.org/TR/xhtml1/#h-4.8 >
You misunderstood the Specification. A CDATA section declaration
is only required if the source code contains markup characters.
This particular script requires the declaration because it has the
`<' character (an STAGO token in PCDATA) in it.
{
var month=x = new Array();
I don't see the point of declaring two variables with the same value
when only one is required.
month [01] = "January";
month [02] = "February";
month [03] = "March";
month [04] = "April";
month [05] = "May";
month [06] = "June";
month [07] = "July";
month [08] = "August";
month [09] = "September";
month [10] = "October";
month [11] = "November";
month [12] = "December";
You might find maintenance simpler if declared as:
var months = ['January','February','March',...'December'];
or
... = new Array("January", ...);
for (i=01;i<x.length;i++)
Counters should not be allowed to escape into the global space, keep
them local:
There is also an octal numeric literal that might not be supported by the
implementation: `01'. It should be 0 for "January". And reducing property
accesses increases efficiency, of course:
for (var i = 0, len = x.length; i < len; i++)
for (var i=01; i<x.length; i++)
{
document.write(x[i] );
This is XHTML, right?
<URL: http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite >
The statement describes the current situation, however the rationale (that
XML would be the reason) is wrong. The statement and the current situation
both contradict the W3C DOM Level 2 HTML Specification (which applies for
XHTML 1.0 documents as well).
Also, consecutive calls of document.write() are inefficient. The output
string should be constructed first and written only once:
// or: ... = new Array();
var out = [];
for (var i = 0, len = x.length; i < len; i++)
{
out.push(x[i]);
}
document.write(out.join(""));
In this case,
document.write(out.join("<br/>\n"));
proves to be more useful. The OP should note that document.write() does not
write lines. There is document.writeln() for that, but it doesn't help with
the markup, and ISTM enjoys not that much a support in implementations.
function doMonths(id) {
var el = (typeof id == 'string')? document.getElementById(id) : id;
function doMonths(el)
{
if (typeof el == 'string')
{
// add feature tests here
el = document.getElementById(el);
}
// ...
}
var i, row, cell, span, monthText;
It would appear that maintenance becomes a lot easier if one takes advantage
of the language feature that variables can be declared near the position
where they are first used instead of on the top of all the code.
if (el && el.rows) {
rows = el.rows;
i = rows.length;
while (i--) {
I recommend using `for' statements for their compactness instead, which
again makes maintenance easier.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7@xxxxxxxxxxxxxxxx>
.
- References:
- With YYYYMMDD Trying to change MM to August
- From: Alan Gresley
- Re: With YYYYMMDD Trying to change MM to August
- From: RobG
- With YYYYMMDD Trying to change MM to August
- Prev by Date: Re: xml 101
- Next by Date: Re: With YYYYMMDD Trying to change MM to August
- Previous by thread: Re: With YYYYMMDD Trying to change MM to August
- Next by thread: Re: With YYYYMMDD Trying to change MM to August
- Index(es):
Relevant Pages
|
Loading