Remove blank lines from a textarea using Prototype

By | February 18, 2009

Here is a JavaScript function used to remove blank lines from a textarea. This snippet is using the Prototype JavaScript framework

function removeBlankLines(field)<br />
{<br />
  $(field).value=$(field).value.gsub(/\s+/, '\r\n');<br />
}

You can use it with “onblur” attribute:

<textarea id="some_text"></textarea>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.