Automatically expanding textboxes and textareas?

Automatically expanding textboxes and textareas?

Hi, anyone any useful code for getting a textbox and/or textarea to expand automatically to fit its contents? Setting width in 'ch' units is too hit and miss. I also need to constrain the width within draggable table column widths so entry controls also need to resize if column widths are changed.

The Reddest
06/17/2009 - 09:07

I don't think there's any easy way to do this. Here's the best approach I can think of:

1. Use an off-screen span to measure the width of your text in pixels. Similar to this approach.

2. Use CSS and the width property to set the width of the textarea in pixels instead of cols based on the width determined by step 1.

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.