HTML Validation

Q

question.boy

I'm am trying to validate my HTML and got the following error
regarding a small javascript segmentin my code

Line 149, Column 40: character "<" is the first character of a
delimiter but occurred as data.
function y2k(number) { return (number < 1000) ? number + 1900 :
number; }

The entire segment is as shown below

<script type="text/javascript" language="javascript">
function y2k(number) { return (number < 1000) ? number + 1900 :
number; }
var today = new Date();
var year = y2k(today.getYear());
document.write(year);
</script>

What do I need to do to fix this error? I'm a little confused that it
is flagging a < symbol inside a javascript function.

Thank you in advance for your advice,

QB
 
S

Steve Pugh

I'm am trying to validate my HTML and got the following error
regarding a small javascript segmentin my code

Line 149, Column 40: character "<" is the first character of a
delimiter but occurred as data.
   function y2k(number) { return (number < 1000) ? number + 1900 :
number; }

The entire segment is as shown below

                <script type="text/javascript" language="javascript">
                        function y2k(number) { return (number < 1000) ? number + 1900 :
number; }
                        var today = new Date();
                        var year  = y2k(today..getYear());
                        document.write(year);
                </script>

What do I need to do to fix this error?  I'm a little confused that it
is flagging a < symbol inside a javascript function.

In HTML the contents of <script> elements are CDATA and hence parsers
look for nothing except the start of an end tag </
However, in XHTML they are PCDATA and hence parsers look for any
markup.

So if you are writing XHTML you should either mark your script blocks
as being CDATA or move all your JavaScript functions that include <
(and some other characters) into external javascript files.

Steve
 
M

+mrcakey

I'm am trying to validate my HTML and got the following error
regarding a small javascript segmentin my code

Line 149, Column 40: character "<" is the first character of a
delimiter but occurred as data.
function y2k(number) { return (number < 1000) ? number + 1900 :
number; }

The entire segment is as shown below

<script type="text/javascript" language="javascript">
function y2k(number) { return (number < 1000) ? number + 1900 :
number; }
var today = new Date();
var year = y2k(today.getYear());
document.write(year);
</script>

What do I need to do to fix this error? I'm a little confused that it
is flagging a < symbol inside a javascript function.

It's because of the X in XHTML. Basically, move your script into an
external .js file (which is good practice anyway) and you should be fine.

+mrcakey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top