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

  • SEARCH
  • Home
  • 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 3211172
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:41:46+00:00 2026-05-17T14:41:46+00:00

In my application there are few <textarea> presents and applied pagination to all these

  • 0

In my application there are few <textarea> presents and applied pagination to all these <textarea>. On a page one <textarea> is displayed.

Assume there are 10 <textarea> exist, then there will be exist 10 pages, one <textarea> on each page.

I have applied auto fit feature to these <textarea>, written below function for this :

function resizeTextarea(id) {

    var minHeight = "75px"; 
    textareaObj = document.getElementById(id);

    var scrollH = textareaObj.scrollHeight+'px';
    if((textareaObj.style.height != scrollH) && (textareaObj.scrollHeight!=0)){
       textareaObj.style.height = scrollH;
    } else
    {
       textareaObj.style.height = minHeight;
    }
}

I have called this function on some events in <textarea> element defination i.e. :

<textarea class="autoGrow" onkeyup="resizeTextarea(this.id);" onchange="resizeTextarea(this.id);" onkeydown="resizeTextarea(this.id);" onmouseup="resizeTextarea(this.id);" onfocus="resizeTextarea(this.id);" style="width:78%;height:75px;overflow:hidden" onclick="resizeTextarea(this.id);" rows="6" cols ="80" id="input"><?php echo decodeChars($textdata) ;?></textarea>

Auto fit feature works properly once user triggers above mentioned events, i.e. onchange,onkeyup,onkeydown.

I stuck to one main problem that, auto fit feature wont work once page get’s load.

for this I have also added below code on document.ready i.e.

$(document).ready(function() {
       if($('.autoGrow')) {
         var setOfElement = $('.autoGrow');
         for(var i = 1 ; i <= setOfElement.length ; i++) {
            resizeTextarea(setOfElement[i].id);
          }
    } 
});

Still facing same problem that, user explicitly needs to click or jumps to <textarea> to work my auto fit feature.

Please folks suggest me any pointers you have.

Your sugggestion will helps me lot.

Thanks

-Pravin

  • 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-05-17T14:41:47+00:00Added an answer on May 17, 2026 at 2:41 pm

    You could (with most of your current code so the calculations are the same) re-write it as a plugin, like this:

    jQuery.fn.resizeTextarea = function(min) {
      min = min || 75; 
      return this.bind("keyup change click focus", function() {
        var sh = this.scrollHeight;
        $(this).height(function(i, h) {
           return h <= sh && sh != 0 ? sh : min;
        });    
      }).trigger("keyup"); //run it once immediately
    };
    

    Then in your document.ready handler, just call that on the elements you want, for example:

    $(function() {
      $('.autoGrow').resizeTextarea();
      //or, as it's written you can pass a different minimum height, for example:
      //$('.autoGrow').resizeTextarea(45);  
    });
    

    You can test it out here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Silverlight 4 application there are few images, both are displayed correctly in design
I have a single page jquery mobile application in which there are few parent
I have an application that's locked down using forms authentication. There are few nightly
When designing an distributed application in Java there seem to be a few technologies
i have inherited a database application from someone else and there are a few
Is there something like SESSION in Windows application? I want to store a few
In my iPhone application, there is a requirement to save a few log files
In my C# 3.5 Windows Forms application, I have a few SplitContainers. There is
I'm using .NET Connector to connect to MySQL. In my application there are few
I'm making an application in which there are few tabs on each tab click

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.