html validator

He has: 59 posts

Joined: Mar 2006

Hi,

im just looking for advice on validating one of my pages. i just need to know why it picks up things like ";" etc in javascript, if you go to http://validator.w3.org/check?uri=http%3A%2F%2Fwww.swiftmediauk.co.uk%2Fwebsite-design.php&charset=%28detect+automatically%29&doctype=Inline

could someone please tell me why it picks up things like that, eg. ; , < , >

Kind Regards,
Andy MacDonald

timjpriebe's picture

He has: 2,667 posts

Joined: Dec 2004

You might try, right before you open and close the Javascript, adding HTML comment tags. Something like this...

&lt;script type="text/JavaScript"&gt;
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
-->
&lt;/script&gt;
'

I'm not 100% sure that will cause it to validate, but you might try it.

WebMaster94's picture

He has: 37 posts

Joined: May 2006

That should work. I've been having the same problem, so I'll try it!

He has: 59 posts

Joined: Mar 2006

hi,

thanks for your reply guys, i did try that but it didnt work for me. I have been told elsewhere that xhtml doesnt like javacode and i have to rap it in {cddata} or something. going to give that a try in a bit. thanks again.

Kind Regards,
Andy MacDonald

Busy's picture

He has: 6,151 posts

Joined: May 2001

These days you don't need the comments, just remove them

of if you want to use the comments, use the

He has: 59 posts

Joined: Mar 2006

Didnt realise that busy, i use a program called internet business promoter and it always flags up about including them.

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

In fact you should definitely not use comments, they will cause your Javascript code to actually be ignored by future browsers. That's when XHTML is served with as application/xhtml+xml instead of text/html

And don't forget that

a Padded Cell our articles site!

He has: 59 posts

Joined: Mar 2006

Ideal, also thanks for the demonstration as well mate. thats really helped. i appreciate it.

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

And all this is why you should try and use external javascript Smiling

He has: 59 posts

Joined: Mar 2006

how do i use external javascript mate? or do you know anywhere that can show me please?

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

&lt;script type="etc" language="etc" src="/path/to/file.js"&gt;&lt;/script&gt;
'

and anything you would have put inside the <script> tags you put in file.js

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Yep, Mr Awesome has a point. It's easier to keep everything as seperate as possible (e.g. instead of using use the AddEventListener function in a seperate Javascript file). JavaScript in one file, HTML in a different file and CSS in another one.

Then you'll have no confusion when you come back to your code in six months time needing to make a change.

a Padded Cell our articles site!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.