...

View Full Version : Show text as formated



Claudio
07-05-2002, 05:41 PM
Hi,

How can we show text as formated onto a web page.

Say the text comes from a Database or you create a few paragrahs in a variable. Now you want to display this on the page as formated. But when I output it, all hard returns, etc. have been removed.

What can I use?

I tried <pre></pre> but this makes the text run off the page cause like in a Word document, it would auto wrap, not with <pre>.

Any ideas?

:confused:

Claudio
07-05-2002, 05:44 PM
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<table width="200" border="1">
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<script>

var t = "This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text \n\n and more text...";

document.write("<pre>"+t+"</pre>");

</script>


</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>

Vladdy
07-05-2002, 06:03 PM
apply overflow: scroll; or overflow: hidden; style (depending on what behaviour you would like to have) to the element containing the text.

adios
07-05-2002, 06:30 PM
Might try a new String method:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">

String.prototype.setHTMLbreaks = function() {
return this.replace(/\n|\r/g, '<br>');
}

</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="1">
<tr>
<td></td><td></td><td></td>
</tr>
<tr>
<td></td><td>
<script type="text/javascript">

var t = "This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text This is some text \n\n and more text...";

document.write(t.setHTMLbreaks());

</script>
</td><td></td>
</tr>
<tr>
<td></td><td></td><td></td>
</tr>
</table>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum