Connecting Tech Pros Worldwide Forums | Help | Site Map

How to validate HTML with variables in link?

deko
Guest
 
Posts: n/a
#1: Jul 20 '05
I use variables in some links on my page. I need to send these variables so
I can change the color of the links in the navbar when the user is on that
page. If you click around on the site you will see the links in the navbar
change:

http://www.clearpointsystems.com/

When I try to validate the page at http://validator.w3.org/ I get the
following error:

Line 120, column 42: an attribute value must be a literal unless it contains
only name characters

<p><span class=blulink><a href=index.php?'home'>Home Page</a></span></p>

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.

If I try to put quotes around the variables, they no longer work:

<p><span class=blulink><a href=index.php?"home">Home Page</a></span></p>
[does not work]

How can I use these variables and still have valid HTML code?

Thanks in advance.



DU
Guest
 
Posts: n/a
#2: Jul 20 '05

re: How to validate HTML with variables in link?


deko wrote:[color=blue]
> I use variables in some links on my page. I need to send these variables so
> I can change the color of the links in the navbar when the user is on that
> page. If you click around on the site you will see the links in the navbar
> change:
>
> http://www.clearpointsystems.com/
>
> When I try to validate the page at http://validator.w3.org/ I get the
> following error:
>
> Line 120, column 42: an attribute value must be a literal unless it contains
> only name characters
>
> <p><span class=blulink><a href=index.php?'home'>Home Page</a></span></p>
>
> 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.
>
> If I try to put quotes around the variables, they no longer work:
>
> <p><span class=blulink><a href=index.php?"home">Home Page</a></span></p>
> [does not work]
>
> How can I use these variables and still have valid HTML code?
>
> Thanks in advance.
>
>[/color]

The validation error message included what to do:
"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."

So,

<p><span class="blulink"><a href="index.php?home">Home Page</a></span></p>

will validate and since you already had

a:link { color:#333399 }
a:visited { color:#333399 }
a:active { color:#333399 }
a:hover { color:#333399 }

a:link img { border:0px }
a:visited img { border:0px }
a:hover img { border:0px }
a:active img { border:0px }

.blulink a:link { color:#333399 }
.blulink a:visited { color:#333399 }
.blulink a:hover { color:#333399 }
.blulink a:active { color:#333399 }

in your stylesheet then you don't need at all to have
..blulink a:link { color:#333399 }
etc

The simple
<p><a href="index.php?home">Home Page</a></p>
will do exactly what you want and will validate without any extra bloat
code.

Your stylesheet indicates you don't know how to use the inheritance
feature of CSS.

DU
deko
Guest
 
Posts: n/a
#3: Jul 20 '05

re: How to validate HTML with variables in link?


<a href="index.php?home">

so *that's* what I need to put quotes around...

Thanks for the help.


Closed Thread