Auto-growing textarea
  
Author:

Here is the small code-snippet which demonstrates how to resize the textarea, so the text could fit its height, without displaying the scrollbars.

var IsIE = document.all?true:false

function textarea_resize(textarea_obj) {
if (textarea_obj.scrollHeight >= 182) // ~ 12 rows maximum
textarea_obj.style.overflow = ''
else {
if (!IsIE) textarea_obj.style.height = 1
textarea_obj.style.height = (textarea_obj.scrollHeight + 15) + 'px' // row height ~ 15 pixels
}
}

Works at least in IE7, FF2/3, Opera 9.


Send by E-mailSend by E-mail   Print versionPrint version
Comments(0)

No comments yet… Be the first to leave comment on this topic!

or
You may sign in using:
Enter with Facebook Enter with Google Enter with VK