Web Analytics Made Easy -
StatCounter Textarea - output not showing linebreaks - CodingForum

Announcement

Collapse
No announcement yet.

Textarea - output not showing linebreaks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Textarea - output not showing linebreaks

    Hello there
    I have a textarea on my website, and when i enter text into it, and if the text has a linebreak in it, it just doesn't read it, and just prints it as 1 line instead of 2 or 3.
    Here is the code
    Code:
    <form name="notes"><textarea id="note" cols="40" rows="5"></textarea><br /><input type='button' onclick='UpdateNotes()' value='Update' /></form>
    Code:
    function UpdateNotes(){
    	var ajaxRequest;  // The variable that makes Ajax possible!
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    
    	// Create a function that will receive data sent from the server
    	ajaxRequest.onreadystatechange = function(){
    		if(ajaxRequest.readyState == 4){
    			var ajaxDisplay = document.getElementById('ajaxDiv');
    			ajaxDisplay.innerHTML = ajaxRequest.responseText;
    		}
    	}
    	var note = document.getElementById('note').value;
    	var ajaxDisplay1 = document.getElementById('ajaxDiv1');
    	ajaxDisplay1.innerHTML = note;
    	
    	
    	var queryString = "?action=update&note=" + note;
    	ajaxRequest.open("GET", "ajax.php" + queryString, true);
    	ajaxRequest.send(null); 
    }
    And when i display for example this text
    "hello
    my friend"
    It will display it as hellomy friend
    Please help

  • #2
    Nothing to do with Ajax.

    Strictly an HTML question.

    *ALL* whitespace in HTML output--including many whitespace characters in a row--is displayed in HTML pages as a *single* ordinary space. And, yes, a line break *IS* considered whitespace.

    If you want to display text that includes linebreaks in HTML so that the linebreaks show, you can either:
    (1) Put the text in between <pre> and </pre> tags.
    or
    (2) Use your server side language or client side JavaScript to convert the line breaks into <br /> tags.
    Be yourself. No one else is as qualified.

    Comment


    • #3
      For textarea's you have end each line with a CRLF. So, to have an empty line you would simply have just CRLF.
      RalphF
      Business Text Messaging Services
      https://www.MobileTextingService.com

      Comment


      • #4
        nl2br() we can solve this problem

        Try This example to solve the problem


        <?php
        if($_POST['txtcomments'])
        {
        echo 'comments'.nl2br($_POST['txtcomments']);
        }
        else
        {
        ?>

        <form method='post' action='textarea.php'>
        <textarea name='txtcomments' style='width:300px;height:300px;' >

        </textarea>
        <input type='submit' value='Click to submit'/>
        </form>

        <?php

        }
        ?>
        Last edited by Dineshphp; Jun 19, 2010, 04:06 AM. Reason: alignment

        Comment


        • #5
          *edit Sorry, I see that bumping old threads is frowned upon. I'll start a new thread.
          Last edited by uparmored; Feb 18, 2012, 05:45 PM.

          Comment

          Working...
          X