W3C home > Mailing lists > Public > www-validator@w3.org > November 2005

Re: decrementing counter causes error [ve][53]

From: Jukka K. Korpela <jkorpela@cs.tut.fi>
Date: Sat, 12 Nov 2005 10:32:48 +0200 (EET)
To: Garth Hamilton <garthah@computan.on.ca>
Cc: www-validator@w3.org
Message-ID: <Pine.GSO.4.63.0511121012090.1694@korppi.cs.tut.fi>

On Fri, 11 Nov 2005, Garth Hamilton wrote:

> <script type="text/javascript"> 
> <!-- hide from incomparible browsers
> 				if (direction == "right") { 
> // if statement to determine  we increment the pointer
> 			++curHorse;			// if moving to right 
> then increment counter curHorse
> 		}
> 		else if (direction == "left") {		// if statement to 
> determine  we decrement the pointer				--curHorse; 
> // if moving to right then decrement counter curHorse			}
> 	// stop hiding from incompatible browsers -->
> </script>
>
> creates an error      should it ?

In XHTML, it is an error; in SGML-based HTML, it is not. So you are 
apparently using XHTML, and naturally the validator reports the error. (By 
the way, you should always post the URL when asking for help in validation 
problems. The URL would let others see the whole problem.)

The characters "--" terminate a comment. The validator gives a good hint:

"invalid comment declaration: found name start character outside comment 
but inside comment declaration"

Technically, though, it's a wrong message. There is no "comment 
declaration" concept in XML and XHTML, just a simplified "comment" 
concept, see http://www.w3.org/TR/REC-xml/#sec-comments

The validator is based on an SGML validator, which has been tuned to
work (somehow) with XML as well. Therefore, its error message in this
case says what an SGML validator would say in a corresponding situation.

An appropriate error message would be something like
"The character pair '--' is not allowed within a comment."

In practice, drop the

<!-- hide ...
// ... -->

stuff. It is of no use (anyone who disagrees, please provide information 
about an actually used browser that fails to recognize <script> elements),
it messes up the code, and in XHTML it is simply wrong: in XHTML, it is
allowed to remove comments before any other processing of a document,
and you don't want that.

Better still, move the script to an external file and refer to it
in a src attribute in <script>.

-- 
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/
Received on Saturday, 12 November 2005 08:32:54 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:20 GMT