Remove blank lines from a textarea using Prototype

February 18, 2009 – 00:03

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

1
2
3
4
function removeBlankLines(field)
{
    $(field).value=$(field).value.gsub(/\s+/, '\r\n');
}

You can use it with “onblur” attribute:

<textarea id="some_text" onblur="removeBlankLines(this)"></textarea>

Tags: , , , ,

Post a Comment