View Full Version : W3C Validation Issue

10-28-2008, 05:56 PM
Hi Guys,

I like to adhere to W3C standards compliant sites whenever I build them.

However I have produced this one site where I need javascript for a certain aspect and basically one part of the javascript is not making the site compliant.

As I am no expert in Javascript I do not know how to get the script to work in an external file so it is in the head tag and one part of the script which contains this greater than sign "<" and it will not validate because it wants it to be &lt; which it cannot be.

Does anybody know how I can validate this page or if I provide the javascript code can someone show me how to make work as an external file.



10-28-2008, 06:05 PM
To make an external file, you just put all of the js code (except the <script> tags) into a new file. Use the file extension .js. Then link to it in your original file like so...

<script language="javascript" src="external.js"></script>

10-28-2008, 08:26 PM
jeremywilken's way is best, but if you absolutely have to include the Javascript in the markup file, enclosing the script in CDATA tags will tell the validator to skip it:

<script type="text/javascript">

10-28-2008, 09:01 PM
You should still comment out the CDATA tags:

<script type="text/javascript">
// <![CDATA[
// ]]>