52 users online (1 members and 51 guests)  


  Results 1 to 4 of 4

Related

  1. reading data line by line from textarea    Forum: ASP Forum
    Replies: 3
  2. Paragraph line breaks lost on preview    Forum: AHFB Feedback
    Replies: 2
  3. Line breaks    Forum: CSS Forum
    Replies: 10
  4. Page Breaks    Forum: ASP Forum
    Replies: 1
  5. Replies: 8
  1. #1
    MTBMaster's Avatar
    New User

    Status
    Offline
    Join Date
    Feb 2010
    Posts
    2

    Line breaks not breaking

    Hi, long time lurker, first post. Thanks for reading this...

    I am having an issue in which I cannot get line breaks/carriage returns to work. I am using the proper escape characters (\n, \r, and so on), but the text never breaks where I want it to.

    I am using this code to change text on a page depending on a dropdown selection; as you can see, the user selects a foreign language and the text will change accordingly. The dropdown code is not shown.

    Here is the code:

    Code:
    var textBlocks = new Array('Welcome to the Johnson Owner\'s Guide.\n To help you get the most out of your Johson product, we\'ve provided you with this owner\'s manual. It\'s fast and efficient, and does lots of awesome things. It\'s also a great way of saving a few trees. Feel free to visit the FAQ on our website, where more info can be found and questions asked and answered. See you soon! Love, Bob', 
    'Chinese intro',
    'Croatian intro',
    'Czech intro',
    'Danish intro',
    'Dutch intro',
    'Finnish intro',
    'French intro',
    'German intro',
    'Greek intro',
    'Hungarian intro',
    'Italian intro',
    'Japanese intro',
    'Korean intro',
    'Latvian intro',
    'Norwegian intro',
    'Polish intro',
    'Portuguese intro',
    'Romanian intro',
    'Russian intro',
    'Spanish intro',
    'Swedish intro',
    'Turkish intro');
    
    function changetext(elemid) { 
    var ind = document.getElementById(elemid).selectedIndex; 
    document.getElementById("display").innerHTML=textBlocks[ind]; 
    }
    The first piece of text in the array is what I am trying to break. As you can see, I tried using \n, to no avail. I also manually entered a Return.

    I am using Dreamweaver CS4 on a Mac to edit the code.

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Line breaks not breaking

    Hi there MTBMaster,

    and a warm welcome to these forums.

    Possibly this example will get you going again...
    Code:
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="language" content="english"> 
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    <title></title>
    
    <script type="text/javascript">
    
    function changetext(){
    
         textBlocks=[
        'Welcome to the Johnson Owner\'s Guide.<br> To help you get the most out of your Johson product, we\'ve provided you with this owner\'s manual.<br> It\'s fast and efficient, and does lots of awesome things.<br> It\'s also a great way of saving a few trees.<br> Feel free to visit the FAQ on our website, where more info can be found and questions asked and answered.<br> See you soon! <br>Love, Bob', 
        'Chinese intro','Croatian intro','Czech intro','Danish intro',
        'Dutch intro','Finnish intro','French intro','German intro',
        'Greek intro','Hungarian intro','Italian intro','Japanese intro',
        'Korean intro','Latvian intro','Norwegian intro','Polish intro',
        'Portuguese intro','Romanian intro','Russian intro','Spanish intro',
        'Swedish intro','Turkish intro'];
    
        obj=document.getElementById('display');
    
    document.getElementById('myselect').onchange=function(){
    
       this.value==''?
       obj.innerHTML='':
       obj.innerHTML=textBlocks[this.value]; 
    
      }
     }
    
    if(window.addEventListener){
       window.addEventListener('load',changetext,false);
     }
    else { 
    if(window.attachEvent){
       window.attachEvent('onload',changetext);
      }
     }
    </script>
    
    </head>
    <body>
    
    <div>
    <select id="myselect">
     <option value=''>-- options --</option>
     <option value='0'>welcome</option>
     <option value='1'>Croatian</option>
     <option value='2'>Croatian</option>
    </select>
    </div>
    
    <div id="display"></div>
    
    </body>
    </html>
    
    

  3. #3
    MTBMaster's Avatar
    New User

    Status
    Offline
    Join Date
    Feb 2010
    Posts
    2

    Thumbs up Re: Line breaks not breaking

    Well, that went straight to the heart--it worked!

    Thank you.

  4. #4
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Line breaks not breaking

    No problem, you're very welcome.



Tags for this Thread