Page 1 of 1

How can I write a link as code ?

Posted: Fri Jun 16, 2006 6:33 am
by brolly
I would like to write a link in code method:

Code: Select all

<a href="http://www.mypage.com">My Page .com</a>
I tried using the textarea method but it does not validate in XHTML 1.1

Does anyone know how to accomplish this ? Is is actually posible ?

Posted: Fri Jun 16, 2006 8:20 am
by tecktalkcm0391
What do you mean as a code? Why do you want it as a code?

Posted: Fri Jun 16, 2006 8:47 am
by feyd
pass it through htmlentities()?

Posted: Fri Jun 16, 2006 10:11 am
by brolly
Here is an example. I would like other web masters to link to my site and just copy and paste my link so they can easily link to my site. I've seen other webs do this but none that were written in xhtml. Unfortunately this does not validate...

Code: Select all

<textarea name="Link to Us" cols="53" rows="4" readonly="readonly">

<a href="http://www.mysite.com">My Site .com</a>

</textarea>

Posted: Fri Jun 16, 2006 10:17 am
by RobertGonzalez
Your textarea name cannot have spaces in it. What is the validator telling your about the validation error?

Posted: Fri Jun 16, 2006 10:23 am
by brolly
Tidy says:

- Warning: discarding unexpected <a>

w3c.org says:

document type does not allow element "a" here.

<a href="http://www.mysite.com">mysite.com</a>

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error)

Posted: Fri Jun 16, 2006 10:29 am
by feyd
I gave a solution.....

Posted: Fri Jun 16, 2006 10:40 am
by RobertGonzalez
That would have been my suggestion as well. I don't think the validator will choke if your code in the textarea are HTML equivalent characters instead of actual code.

Posted: Fri Jun 16, 2006 10:43 am
by brolly
I fixed the name of the textarea but all the validators still state (notice the character in bold):

The element 'http://www.w3.org/1999/xhtml:textarea' cannot contain child element 'http://www.w3.org/1999/xhtml:a' because the parent element's content model is text only. (35:2)
<a href="http://www.mysite.com">my site .com</a>

Posted: Fri Jun 16, 2006 11:04 am
by RobertGonzalez
Change this...

Code: Select all

<a href="http://www.mysite.com">my site .com</a>
to...

Code: Select all

<a href="http://www.mysite.com">my site .com</a>

Posted: Fri Jun 16, 2006 11:15 am
by brolly
That did it ! You guys are definitely gurus !

Posted: Fri Jun 16, 2006 11:19 am
by John Cartwright
brolly wrote:That did it ! You guys are definitely gurus !
Feyd gave you an answer in the 3rd post, please pay attention.

Posted: Fri Jun 16, 2006 11:27 am
by brolly
Yes, you're right and I did read it thoroughly but I am an amateur that has never studied computers and have made my site solely by reading tutorials. I simply did not understand that php but after a few months of tutorials I have gotten a grasp on xhtml.

Posted: Fri Jun 16, 2006 11:38 am
by John Cartwright
brolly wrote:Yes, you're right and I did read it thoroughly but I am an amateur that has never studied computers and have made my site solely by reading tutorials. I simply did not understand that php but after a few months of tutorials I have gotten a grasp on xhtml.
That is perfectly acceptable, but instead of ignoring his solution you could perhaps ask us to elaborate if you are still confused :wink: No biggie.

Posted: Fri Jun 16, 2006 11:44 am
by brolly
Ok, I understand your point, it was not my intention. :mrgreen: