Results 1 to 4 of 4

Thread: Remove line breaks from text field

  1. #1
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Remove line breaks from text field

    I've got a contact us form on a website that I use to get information from customers. I copy/paste the info they submit into a database. The problem being, that when the enter in comments in the text area, sometimes they press enter and add line breaks. What would I use as a script to automatically remove line breaks from this field so when the form is submitted, I get one long string?

    Thanks in advance.

  2. #2
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm assuming you're using some server-side scripting since you're putting stuff in a database, so here's how to do it with php.

    Code:
    $message = "Hello \r\n my \n name is \r Blake";
    
    $message = str_replace(Array("\r\n","\n","\r"), "<br>", $message);
    
    echo $message;
    Output:

    Code:
    Hello <br> my <br> name is <br> Blake
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

  3. #3
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default


    I'm actually looking for a JavaScript I can put on my webform that will remove the line breaks from the text area field so all I have to do is copy/paste into my database. My webform is basic html on an asp page.

    Thank you for your help.

  4. #4
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, I assumed you were automatically inserting the text into the database, which would have required server-side scripting.

    This will do it with javascript:

    Code:
    var message = "Hello \r\n my \n name is \r Blake";
    
    message = message.replace(/\r\n|\r|\n/g, "<br>");
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

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
  •