Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Show text as formated

    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?


  • #2
    New Coder
    Join Date
    Jul 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Here's some sample

    <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>

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    apply overflow: scroll; or overflow: hidden; style (depending on what behaviour you would like to have) to the element containing the text.
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •