Comments and javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Comments and javascript

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

look up CDATA sections in XML and use an XHTML doctype.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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">
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

*bump*

when I use the cdata thing in my javascript, the script does not get executed, like its been commented out. Anything?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

this took me forever to find
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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 (
Post Reply