PDA

View Full Version : Javascript and xhtml validation


Daybreak_0
11-15-2003, 09:22 PM
I am validating my xhtml, but the W3C validator is throwing up errors on any javascript I have for example -


<p><script language="JavaScript"><!--
document.write(emailTopress());
// --></script>. (President)</p><br>
<p><script language="JavaScript"><!--
document.write(emailTosec());
// --></script> (Secretary)</p>


the validation has problems with the <!-- and later // --> and the way they are used.

I do not understand why these are used, and in one lot of javascript I removed them. It did not make a difference, but I hate not knowing why someone would have put them there in the first place. Can anyone tell me what they are for and whether I should keep them in.

Thanks
Day

Dynasty
11-15-2003, 10:24 PM
I'm not entirely sure but couldn't you put the javascript elements into a .js file, and just use the script tag to link to it?

Daybreak_0
11-16-2003, 12:55 AM
The functionality behind the above is in. a JS file

Editedmind
11-16-2003, 01:14 AM
Well I haven't noticed anything strange with the script code, however in xhtml you should close of every tag. This means you should really break a line like this <br/> or <br /> as I usually do. Actually I even do this for standard html as I find it offers more understandable stucture in the sourcecode.

So perhaps it is the <br> that the validator snagged up on.

Daybreak_0
11-16-2003, 04:00 AM
Apologies should have taken out that <br> tag, have already fixed that.

Error is still there, please disregard that tag.

Regards
Day

DCElliott
11-16-2003, 11:15 AM
You need to wrap your script in a CDATA construct:<script type="text/javascript">
<!-- <![CDATA[
javascript goes here
//]]> -->
</script>Here is a list of validation resources if anyone is interested: http://checky.mozdev.org/Services/

DE