SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Oct 2003
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove lines when pasting?

    This would prevent new line on textarea when pressing enter key:

    $('#text_description').keypress(function(e) {
    if(e.keyCode == 13) { e.preventDefault() }
    });

    but how to remove lines when pasting into text area?
    [Home Sweet Home]

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The easiest way is to take the entire contents of the textarea, remove the newlines using a regular expression, and replace the contents with the new string. The difficulty is listening for the "pasting" event, which is especially difficult when the user has dragged text in or used the mouse's context menu. There is a newish "onpaste" event, but it is unsupported across browsers. So you can use "onpaste" but you will also have to use onkeyup (for ctrl+v) and onchange (for context menu paste).


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
  •