SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    AJAX - textarea losing new line

    Hi All,

    I'm having a problem preserving new lines.

    Code:
    		function getScriptPage(div_id,content_id0,content_id1) {
    
    			subject_id = div_id;
    content0 = document.getElementById(content_id0).value;
    content1 = document.getElementById(content_id1).value;
    			
    query = "Comments=" + content0 + "&type=" + content1;
    
    http.open("GET", "index.php?" + (query) , true);
    
    			http.onreadystatechange = handleHttpResponse;
    			http.send(null);
    		}
    //and for the form
    
    
    <input type="submit" id="Submit_Button" value="" onClick="getScriptPage('output_div','Comments','type')">
    There is also an external ajax script that handles the http GET response
    Code:
    	subject_id = '';
    	function handleHttpResponse() {
    		if (http.readyState == 4) {
    			if (subject_id != '') {
    				document.getElementById(subject_id).innerHTML = http.responseText;
    			}
    		}
    	}
    	function getHTTPObject() {
    		var xmlhttp;
    		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    			try {
    				xmlhttp = new XMLHttpRequest();
    			} catch (e) {
    				xmlhttp = false;
    			}
    		}
    		return xmlhttp;
    	}
    	var http = getHTTPObject(); // We create the HTTP Object
    If you use line feeds in the Comments textarea they do not get passed on when submitted.

    print_r($_GET);

    shows:
    Array
    (
    [Comments] => thesearenewlines
    [type] => Inquire
    )

    (I'm using super ajax programming seed)

    Can someone help me preserve the \r\n so I can deal with them in my form processing. I am totally lost here.

    Thank You.
    Loren
    Last edited by lorenw; Jul 31, 2007 at 09:32. Reason: added the extenal js code

  2. #2
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    After more searching I believe the culprit to be innerHTML and saw mention of innerText which doesn't seem to pass the name, value fields.

    I have a temp fix.
    .value.replace(/\n/g, "<br>")


Bookmarks

Posting Permissions

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