Page 1 of 1

New lines from JavaScript

Posted: Thu Jun 19, 2008 1:31 pm
by Arocity
I am using a GET to get the value from a text area. I want to keep the newlines/carriage returns since this is basically a notepad function. For some reason, I'm not keeping/transforming the new lines. My AJAX response is simply all one line. FYI, I did an alert from my javascript function to verify that the new lines are being sent.

Code: Select all

$bullet_pad = nl2br($_GET["pad"]);
$what = addslashes($_GET["what"]);
 
$thisMonth = date("m");
    if($this_em_id == $em_id)
    {
        if ($what == 1)
        {
            echo "<h1>Final Draft</h1>";
            
            $current_bullet_q = "SELECT bullet_pad FROM " . _t_bullets . " WHERE month='$thisMonth' and em_id='$this_em_id'";
            $current_bullet = $db->get_var($current_bullet_q);
 
            echo nl2br($current_bullet);
            echo "<br />";
            echo nl2br($bullet_pad);
        }
    }

Re: New lines from JavaScript

Posted: Thu Jun 19, 2008 1:56 pm
by WebbieDave
Arocity wrote:FYI, I did an alert from my javascript function to verify that the new lines are being sent.
An alert in itself does not guarantee that newlines even exist in the string that's being displayed. Javascript implementations will display a long string in an alert box on several lines if there are spaces present. Also, textareas with no horizontal scrollbars will appear to break the text into different lines when, in actually, it is POSTed with no newlines.

Re: New lines from JavaScript

Posted: Thu Jun 19, 2008 2:09 pm
by Arocity
WebbieDave wrote:An alert in itself does not guarantee that newlines even exist in the string that's being displayed. Javascript implementations will display a long string in an alert box on several lines if there are spaces present.
I thought about that. When I did the alert, I simply used "a \n b \n c". Of course not with the actual "\n"'s. The alert windows still showed each character on a separate line. This should eliminate both of your possibilities, correct?
Also, textareas with no horizontal scrollbars will appear to break the text into different lines when, in actually, it is POSTed with no newlines.
I'm pretty sure that depends on the attributes you have set for that textarea box, particularly the "wrap" attribute. If you set it to "none", you won't get scrollbars.

Re: New lines from JavaScript

Posted: Thu Jun 19, 2008 2:33 pm
by WebbieDave
Well, if you're sure newlines are being posted, you'll need to find out where they're being stripped. Try hitting the URL yourself (sans ajax) to see if the output is as expected. If so, your Ajax lib may be stripping them.