Page 1 of 1

Comments and javascript

Posted: Wed Aug 23, 2006 9:44 am
by shiznatix
Hey ho!

So I am trying to get all my pages to validate perfectly. Going alright except this javascript stuff is holding me back. The problem is I am using the safe comment thingys so the JS isnt parsed as HTML. Well we have problems with this, like example:

Code: Select all

<script type="text/javascript">
<!--
    //skip a bunch of lines
    optn.text = '---Any---';
    //finish it off
the problem is that it takes every occurance of '--' as starting the end or beginning comment tag. This is what the validator says:
invalid comment declaration: found name character outside comment but inside comment declaration.
How do I fix this?

Next Problem!

I try to do this:

Code: Select all

<noscript>(full name)</noscript>
but the validtor says:
character data is not allowed here.
I don't get it.

Last Problem (I hope)!

I try this code:

Code: Select all

document.write("<option value=\"1\">Allegheny</option>");
and I get this error:
an attribute value must be a literal unless it contains only name characters
*snip*
You have used a character that is not considered a "name character" in an attribute value. Which characters are considered "name characters" varies between the different document types, but a good rule of thumb is that unless the value contains only lower or upper case letters in the range a-z you must put quotation marks around the value. In fact, unless you have extreme file size requirements it is a very very good idea to always put quote marks around your attribute values. It is never wrong to do so, and very often it is absolutely necessary.
As I translated that, I have to put quotes around it, which I did. I don't get it.

Posted: Wed Aug 23, 2006 5:48 pm
by Ollie Saunders
look up CDATA sections in XML and use an XHTML doctype.

Posted: Wed Aug 23, 2006 7:05 pm
by shiznatix
i am using XHTML doctype.

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Posted: Fri Aug 25, 2006 1:06 am
by shiznatix
*bump*

when I use the cdata thing in my javascript, the script does not get executed, like its been commented out. Anything?

Posted: Fri Aug 25, 2006 3:48 am
by Ollie Saunders
this took me forever to find

Posted: Fri Aug 25, 2006 10:47 am
by shiznatix
holy wow thank you for that, big help.

The only thing that I still have a question about is the:

Code: Select all

<noscript>(full name)</noscript>
thing. That was not explained and thus still makes no sence.

Posted: Fri Aug 25, 2006 11:35 am
by Ollie Saunders
Validator bug? Ambush Commander will vouch that the validator is by no means perfect.
You could try moving the noscript somewhere else or putting it in a div (or taking it out) maybe leaving a space before (