How can I write a link as code ?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

How can I write a link as code ?

Post 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 ?
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

What do you mean as a code? Why do you want it as a code?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

pass it through htmlentities()?
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post 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>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Your textarea name cannot have spaces in it. What is the validator telling your about the validation error?
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post 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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I gave a solution.....
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post 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>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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>
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post by brolly »

That did it ! You guys are definitely gurus !
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post by brolly »

Ok, I understand your point, it was not my intention. :mrgreen:
Post Reply