Solved

Resize textare field as text is entered

Posted on 2014-01-21
8
217 Views
Last Modified: 2014-01-21
The solution here works for changing the height dynamically.

http://jsfiddle.net/FNMSP/2/

1.  I need it to auto-shorten the height of the textarea when text is erased (the reverse of what is doing now )

2. I also need that the width of the textarea resizes automatically (shorten or  lenghten)
So it will enlarge till reaching a max-width, then will start increasing the height.

Thank you!
0
Comment
Question by:myyis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39797648
Since you are using MooTools
http://mootools.net/forge/p/form_autogrow

For the width - that would be an unusual one since the textarea would automatically wrap so there is no defined width to calculate.
0
 
LVL 1

Author Comment

by:myyis
ID: 39797720
Is it possible with pure JS?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39797733
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 1

Author Comment

by:myyis
ID: 39797754
I don't use jquery
0
 
LVL 58

Expert Comment

by:Gary
ID: 39797808
http://jsfiddle.net/GaryC123/eq554/5/

<textarea onkeyup="autogrow(this)"></textarea>
<style>
textarea {
    min-height:50px;
    overflow:hidden;
}
</style>
<script>
    function autogrow(textField) {
    rows = textField.value.split("\n").length + 1
    textField.style.height = (rows * 14) + "px";
    }
</script>

Open in new window

0
 
LVL 1

Author Comment

by:myyis
ID: 39798433
Thank you it is very like to what I wanted to do.
The only problem is that if I don't use enter button and keep writing it does not work.
Any idea?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39798466
0
 
LVL 1

Author Comment

by:myyis
ID: 39798534
great! thank you.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question