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)
{
  $(field).value=$(field).value.gsub(/\s+/, '\r\n');
}

You can use it with “onblur” attribute:

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

Leave a Reply