Skip to content

Instantly share code, notes, and snippets.

@tsmango
Created September 18, 2009 20:23
Show Gist options
  • Save tsmango/189275 to your computer and use it in GitHub Desktop.
Save tsmango/189275 to your computer and use it in GitHub Desktop.
<!-- Automatically resize a textarea's height (like Facebook) -->
<textarea id="comment" rows="1" cols="50"></textarea>
<script type="text/javascript" charset="utf-8">
function autoResize(fieldId) {
var length = $(fieldId).value.length;
if(length > 0) {
$(fieldId).rows = Math.floor(length / $(fieldId).cols) + 1;
} else {
$(fieldId).rows = 1
}
}
$('comment').observe('keyup', function(){autoResize('comment');});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment