Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<pre> tag not working ...

Status
Not open for further replies.
The pre tag stands for Pre-Formatted.

It means it will keep any formatting the text has. Like spaces, and line breaks etc...


What exactly did you expect it to do on a link with no formatting since its a single word?>


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Well I want to display the code. I don't want it to behave as a link.
Is there a way?
 
audiopro take a bow. Give that man (or woman) a gold star. By specifying no border and overflow:auto it doesn't look like a text area.
Many thanks.
 
Usually to accomplish this you need to replace < and > and other tag characters with their encoded equivalents.
< for <

and

> for >

Code:
[red]<[/red]a href="[URL unfurl="true"]http://www.server.com/page.html"[/URL][red]>[/red] Link[red]<[/red]/a[red]>[/red]




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi

Actually, the less-than ( < ) and greater-than ( > ) characters can not appear inside a [tt]textarea[/tt] element. So you have to write them as character entities, as Phil suggested. Then why the [tt]textarea[/tt] anyway ?

Note, that unfortunately the character entities were replaced in Phil's post, but he means this :
Code:
[red]&lt;[/red]a href="[URL unfurl="true"]http://www.server.com/page.html"[/URL][red]&gt;[/red]Link[red]&lt;[/red]/a[red]&gt;[/red]

Feherke.
 
I use the textarea element a lot, to show example code on web pages.
Code:
<textarea rows="4" cols="40">
<a href='newlink.cgi'>Newlink</a>
</textarea>
Works for me.

Keith
 
Right click and look at the source to see the textarea tags.
 
Hi

dexeloper said:
Right click and look at the source to see the textarea tags.
Ok, now is there. Now you can ask the validator :
W3C Markup Validation Service said:
[COLOR=white red] X [/color] Line 8, Column 68: document type does not allow element "A" here

…[tt]"";return true;' href='[red]>[/red]Intranet</a></textarea>[/tt]

Feherke.
 
It does not validate, since anchor element should not exist inside a textarea. Furthermore, your visitors may freely type in the textarea field. In the least, you should add [tt]readonly="readonly"[/tt] to the textarea attributes.

[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Beside that, in most browsers textarea's content can not be selected together with the page content. Which I find irritating.
I use them to allow snippets of code to be easily cut and pasted into users web pages. The users of these sites are not usually interested in the whole web page.

It does not validate
It breaks the rules but can this cause problems?

your visitors may freely type in the textarea field
The textarea examples on my pages are not within form tags, therefore cannot be submitted but can this still cause problems?

Keith
 
Apologies, should have checked the preview before submitting it. But yes feherke is right that is what I meant.

As far as textareas and code go, all code should be run through a coder function to change all html entities into their encoded equivalents.

It makes the contents valid, and makes sure no unexpected renderings can occur.

Breaking validation can lead to undesired effects. You have no idea how browsers may decide to treat it. They may attempt to render the contents of the textarea or something equally unexpected. Additionally it may break the rest of the page if the tags are left opened etc..

By the same token, screen readers cannot tell the difference between the actual code that renders the page and the sample code in your textarea if they are not encoded. This may cause confusion to the people that use these screen readers.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
looking at your code, you're using ASP as your scripting platform - even though the page you referenced id HTML, the link takes the user back to:

Code:
[URL unfurl="true"]http://intranet/home.asp[/URL]

so why not use this (without the textarea). You'll have to save the page as ".asp", but it will take care of all the character encoding for you.

Code:
<%=server.HTMLEncode("<a href='newlink.cgi'>Newlink</a>")



--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top