Re: Javascript form validation - comments please
On Fri, 5 Dec 2003 23:38:13 +0000, Dr John Stockton
<spam@merlyn.de mon.co.uk> wrote:
[color=blue]
>JRS: In article <e4d0tvcdpgst9e tpqcbvkq4udsb91 7crk4@4ax.com>, seen in
>news:comp.lang .javascript, Stephen Poley <sbpoley@xs4all .nl> posted at
>Fri, 5 Dec 2003 08:35:40 :-[color=green]
>>
>>http://www.xs4all.nl/~sbpoley/webmatters/formval.html
>>
>>I would be interested in comments, suggested improvements etc.[/color][/color]
[color=blue]
>W3's free TIDY said :
>
>line 9 column 5 - Warning: inserting "type" attribute for <link> element[/color]
Bit redundant, as the stylesheet is not specific to any particular media
type.
[color=blue]
>line 101 column 1 - Warning: <table> lacks "summary" attribute[/color]
Added.
[color=blue]
>line 180 column 1 - Warning: trimming empty <p>[/color]
There is no <p> at or near line 180
[color=blue]
>line 104 column 9 - Warning: Attribute "size" not supported in HTML 4.01
>line 111 column 9 - Warning: Attribute "size" not supported in HTML 4.01
>line 118 column 9 - Warning: Attribute "size" not supported in HTML 4.01
>line 125 column 9 - Warning: Attribute "size" not supported in HTML 4.01[/color]
Incorrect, as pointed out by Nick.
[color=blue]
>The page currently lacks, AFAICS in MSIE 4 : Author name, date of
>editing, links to homepage.[/color]
Links are (and were) present. Date added. I don't bother to put my name
on every page - maybe I could.
[color=blue]
>I entered xx in the first box; it thought a bit, and remarked "Line 66
>Char 3 'undefined' is undefined"[/color]
This will be one of the points Richard raised. I didn't realise that
undefined was undefined (!) in the first few versions of Javascript.
[color=blue]
> (Line 66 does not hold script).[/color]
Yes, well - better talk to your browser supplier about that. <g>
[color=blue]
>This
>appears to be all that it will do, except that the Send button also
>tries to contact your Web site - without success, as I am offline. You
>could add, apart from the ostensible form, a control to adapt behaviour
>for off-line use.[/color]
I think it reasonable to assume that the user understands that 'send'
will not do a great deal when offline.
[color=blue]
>You invite source viewing. Since you do not know what it will be viewed
>with, ISTM that both HTML and script should be formatted for a
>72-character right margin.[/color]
Interesting point. I think however that it is reasonable to expect that
anyone viewing HTML source should have an editor/viewer capable of
coping with longer lines. The script is already mostly less than 72
characters wide, with those lines which are longer being longer for a
reason.
[color=blue]
>I would change the NOSCRIPT to acknowledge that enabling may be
>impossible - ... "disabled" -> "not enabled" & "If you can enable it
>..." is perhaps adequate but not ideal.[/color]
Fair enough.
[color=blue]
>The ostensible wording is good; there is a split infinitive in
>formval.js <g>.[/color]
I decided to deliberately ignore this comment. <g>
[color=blue]
>I think formval.js Line 66 is :
> if (document.getEl ementById == undefined)
>
>Should that be "'undefined '"? I like using "var U" to define an
>undefined variable ... but you could put "var undefined" ... .[/color]
See note above.
[color=blue]
>By using proceed instead of continu you could obviate a comment.[/color]
Agreed - done.
[color=blue]
>Your actual validity-testing could be shortened by using the approach of
>my js-valid.htm .[/color]
Well, your code is certainly impressively brief. But I feel mine is
easier to understand, and also more flexible for e.g. putting up
warnings when an input is likely to be incorrect but is not definitely
so. Compactness is not as important as it used to be, with faster modems
and HTTP data-compression. Maybe still important for mobile connections
using 9.6 Kbps, but I'm not sure how many of those devices support
Javascript anyway.
[color=blue]
>IIRC, someone posted an implementation of getElementById for older
>browsers in c.l.j a while ago. Yes, ...[/color]
Thanks, but on the whole I'd prefer to stick to standard Javascript
except where it's necessary to support a very widely used browser (i.e.
IE 5/6)
I've put up a new version of the page.
--
Stephen Poley
On Fri, 5 Dec 2003 23:38:13 +0000, Dr John Stockton
<spam@merlyn.de mon.co.uk> wrote:
[color=blue]
>JRS: In article <e4d0tvcdpgst9e tpqcbvkq4udsb91 7crk4@4ax.com>, seen in
>news:comp.lang .javascript, Stephen Poley <sbpoley@xs4all .nl> posted at
>Fri, 5 Dec 2003 08:35:40 :-[color=green]
>>
>>http://www.xs4all.nl/~sbpoley/webmatters/formval.html
>>
>>I would be interested in comments, suggested improvements etc.[/color][/color]
[color=blue]
>W3's free TIDY said :
>
>line 9 column 5 - Warning: inserting "type" attribute for <link> element[/color]
Bit redundant, as the stylesheet is not specific to any particular media
type.
[color=blue]
>line 101 column 1 - Warning: <table> lacks "summary" attribute[/color]
Added.
[color=blue]
>line 180 column 1 - Warning: trimming empty <p>[/color]
There is no <p> at or near line 180
[color=blue]
>line 104 column 9 - Warning: Attribute "size" not supported in HTML 4.01
>line 111 column 9 - Warning: Attribute "size" not supported in HTML 4.01
>line 118 column 9 - Warning: Attribute "size" not supported in HTML 4.01
>line 125 column 9 - Warning: Attribute "size" not supported in HTML 4.01[/color]
Incorrect, as pointed out by Nick.
[color=blue]
>The page currently lacks, AFAICS in MSIE 4 : Author name, date of
>editing, links to homepage.[/color]
Links are (and were) present. Date added. I don't bother to put my name
on every page - maybe I could.
[color=blue]
>I entered xx in the first box; it thought a bit, and remarked "Line 66
>Char 3 'undefined' is undefined"[/color]
This will be one of the points Richard raised. I didn't realise that
undefined was undefined (!) in the first few versions of Javascript.
[color=blue]
> (Line 66 does not hold script).[/color]
Yes, well - better talk to your browser supplier about that. <g>
[color=blue]
>This
>appears to be all that it will do, except that the Send button also
>tries to contact your Web site - without success, as I am offline. You
>could add, apart from the ostensible form, a control to adapt behaviour
>for off-line use.[/color]
I think it reasonable to assume that the user understands that 'send'
will not do a great deal when offline.
[color=blue]
>You invite source viewing. Since you do not know what it will be viewed
>with, ISTM that both HTML and script should be formatted for a
>72-character right margin.[/color]
Interesting point. I think however that it is reasonable to expect that
anyone viewing HTML source should have an editor/viewer capable of
coping with longer lines. The script is already mostly less than 72
characters wide, with those lines which are longer being longer for a
reason.
[color=blue]
>I would change the NOSCRIPT to acknowledge that enabling may be
>impossible - ... "disabled" -> "not enabled" & "If you can enable it
>..." is perhaps adequate but not ideal.[/color]
Fair enough.
[color=blue]
>The ostensible wording is good; there is a split infinitive in
>formval.js <g>.[/color]
I decided to deliberately ignore this comment. <g>
[color=blue]
>I think formval.js Line 66 is :
> if (document.getEl ementById == undefined)
>
>Should that be "'undefined '"? I like using "var U" to define an
>undefined variable ... but you could put "var undefined" ... .[/color]
See note above.
[color=blue]
>By using proceed instead of continu you could obviate a comment.[/color]
Agreed - done.
[color=blue]
>Your actual validity-testing could be shortened by using the approach of
>my js-valid.htm .[/color]
Well, your code is certainly impressively brief. But I feel mine is
easier to understand, and also more flexible for e.g. putting up
warnings when an input is likely to be incorrect but is not definitely
so. Compactness is not as important as it used to be, with faster modems
and HTTP data-compression. Maybe still important for mobile connections
using 9.6 Kbps, but I'm not sure how many of those devices support
Javascript anyway.
[color=blue]
>IIRC, someone posted an implementation of getElementById for older
>browsers in c.l.j a while ago. Yes, ...[/color]
Thanks, but on the whole I'd prefer to stick to standard Javascript
except where it's necessary to support a very widely used browser (i.e.
IE 5/6)
I've put up a new version of the page.
--
Stephen Poley
Comment