Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:29:59+00:00 2026-06-13T23:29:59+00:00

I have certain piece of code which enables me to type in textarea. I

  • 0

I have certain piece of code which enables me to type in textarea. I am increasing width of textarea on keypress and i am giving width a limit after which it should stop increasing. What i want is on width limit reach stop typing and when user press enter key start typing again.

Heres Sample code :

var maindivwidth = $('.maindiv').width();           
var vWidth = 0;
var hIncr = 2;   
var tWidth = $('textarea')[0].value.length;
var iheight = $(dividfortextbox).css('font-size').replace('px','');

$(dividfortextbox).keypress(function(e) {

if ((e.keyCode || e.which) == 13) {

$(this).parent(dividfortext).css('height', (hIncr * iheight) + 'px');
  vWidth = 0;
  hIncr++;
}
else 
{       
    vWidth = (vWidth+1);

 if (tWidth < maindivwidth-aminus && vWidth*9 > tWidth){
 tWidth = vWidth*9;
 $(this).parent(dividfortext).css('width', (tWidth) + 'px');

 }
 else{
    ??????????????????????????
 } 

 }
 });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:30:01+00:00Added an answer on June 13, 2026 at 11:30 pm

    If I got you right, this may be what you’re looking for: Auto grow text area (jsFiddle)

    No need for the user to press enter here to continue writing, the textarea automatically expands vertically. Depending on the nature of your project, this – although far from perfect! – might very well do the job. Please note that this method requires jQuery, although obviously it can be done without it.

    HTML

    <div id="textareaContainer">
       <textarea id="expandTextArea"></textarea>
    </div>
    

    CSS

    #expandTextArea {
    padding:8px 1%;
    height:20px;
    width:160px;
    font-size:16px;
    color:#242424;
    border:1px solid #333;
    
    /*important for getting the smooth expansion effect*/
    -webkit-transition: height 0.6s;
    -webkit-transition-timing-function: height 0.6s; 
    -webkit-transition: width 0.6s;
    -webkit-transition-timing-function: width 0.6s;
    
    overflow:hidden;
    }
    

    Jquery

    $('textarea#expandTextArea').live('keydown', function() {
    
    //insert your values here
    var expandTextareaAfter = 20; //characters, grow horizontally
    var breakRowAfter = 50; // characters, grow vertically
    var fontSize = 16; //textarea fontsize in px
    
    var ta = $("#expandTextArea");
    var nrOfLetters = ta.val().length;
    var newWidth = (nrOfLetters*9);
    
    //check if textarea is full and expand the textarea horizontally/vertically
    if ((nrOfLetters >= expandTextareaAfter) && (nrOfLetters <= breakRowAfter)) {
        ta.css("width", newWidth+"px");
    } else if (nrOfLetters > expandTextareaAfter) {
        ta.css("height", ((fontSize+1) * (Math.round(nrOfLetters/breakRowAfter))) + "px");
    }
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have certain piece of code which helps me to save the image on
I am having a piece of code in which i delegate certain properties of
I have the following piece of code, which I want to make parallel in
I have a piece of code related to MapKit which works fine on my
I have a simple java program which is just a single piece of code
I'm having some problems with a certain piece of code which sits in my
I have a piece of code which compiles without problems with x86 gcc 4.4.1
I'm writing a piece of code in which I have to cast an Object
I have the below piece of code which Prefixs a string to the start
I am new to socket programming, and have a piece of code which opens

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.