Automatyczne zaznaczanie pola tekstowego przy użyciu prototypu

Obecnie pracuję nad wewnętrzną aplikacją sprzedażową dla firmy, dla której pracuję, i mam formularz, który pozwala użytkownikowi zmienić adres dostawy.

Teraz myślę, że wyglądałoby to o wiele ładniej, gdyby textarea, którego używam do głównych danych adresowych, zajmowałaby obszar tekstu w nim i automatycznie zmieniała rozmiar, jeśli tekst został zmieniony.

Oto zrzut ekranu z tej chwili.

Adres ISO

Jakieś pomysły?

@ Chris

Dobry punkt, ale są powody, dla których chcę go zmienić rozmiar. Chcę, aby obszar, który zajmuje, był obszarem informacji w nim zawartych. Jak widać na zrzucie ekranu, jeśli mam stały textarea, zajmuje sporo miejsca w pionie.

Mogę zmniejszyć czcionkę, ale adres musi być duży i czytelny. Teraz mogę zmniejszyć rozmiar obszaru tekstowego, ale potem mam problemy z ludźmi, którzy mają linię adresu, która zajmuje 3 lub 4 (jedna zajmuje 5) linii. Konieczność użycia przez użytkownika scrollbar jest głównym Nie-Nie.

Chyba powinienem być bardziej konkretny. Jestem po zmianie rozmiaru w pionie, a szerokość nie ma większego znaczenia. Jedynym problemem, który się z tym dzieje, jest numer ISO (duży "1") zostaje wciśnięty pod adres, gdy szerokość okna jest zbyt mała (jak widać na zrzucie ekranu).

Nie chodzi o to, aby mieć gimicka; chodzi o to, aby mieć pole tekstowe, które użytkownik może edytować, które nie zajmie niepotrzebnego miejsca, ale pokaże cały tekst w to.

Jeśli jednak ktoś wymyśli inny sposób podejścia do problemu, to też jestem na to otwarty.
Zmodyfikowałem trochę kod, bo dziwnie się zachowywał. Zmieniłem go, aby aktywować na keyup, ponieważ nie bierze pod uwagę postaci, która została właśnie wpisana.
resizeIt = function() {
  var str = $('iso_address').value;
  var cols = $('iso_address').cols;
  var linecount = 0;

  $A(str.split("\n")).each(function(l) {
    linecount += 1 + Math.floor(l.length / cols); // Take into account long lines
  })

  $('iso_address').rows = linecount;
};
Author: Peter Mortensen, 2008-08-11

18 answers

Facebook robi to, gdy piszesz na ścianach ludzi, ale zmienia rozmiar tylko pionowo.

Pozioma zmiana rozmiaru wydaje mi się bałaganem, ze względu na zawijanie słów, długie linie i tak dalej, ale pionowa zmiana rozmiaru wydaje się być dość bezpieczna i miła.

Żaden z Facebook-using-newbies, które znam, nigdy nie wspomniał o tym ani nie był zdezorientowany. Użyłbym tego jako anegdotycznego dowodu, aby powiedzieć "śmiało, wdrożyć to".

Jakiś kod JavaScript aby to zrobić, używając Prototype (ponieważ to mi się kojarzy):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <script src="http://www.google.com/jsapi"></script>
        <script language="javascript">
            google.load('prototype', '1.6.0.2');
        </script>
    </head>

    <body>
        <textarea id="text-area" rows="1" cols="50"></textarea>

        <script type="text/javascript" language="javascript">
            resizeIt = function() {
              var str = $('text-area').value;
              var cols = $('text-area').cols;

              var linecount = 0;
              $A(str.split("\n")).each( function(l) {
                  linecount += Math.ceil( l.length / cols ); // Take into account long lines
              })
              $('text-area').rows = linecount + 1;
            };

            // You could attach to keyUp, etc. if keydown doesn't work
            Event.observe('text-area', 'keydown', resizeIt );

            resizeIt(); //Initial on load
        </script>
    </body>
</html>

PS: oczywiście ten kod JavaScript jest bardzo naiwny i nie jest dobrze przetestowany, i prawdopodobnie nie chcesz go używać na skrzynkach tekstowych z powieściami w nich, ale masz ogólny pomysł.

 71
Author: Orion Edwards,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:56:16

Jednym z udoskonaleń niektórych z tych odpowiedzi jest pozwolić CSS zrobić więcej pracy.

Podstawowa trasa wydaje się być:

  1. Tworzenie elementu kontenera do przechowywania textarea i ukrytego div
  2. używając Javascript, zachowaj synchronizację zawartości textarea z div'S
  3. pozwól przeglądarce wykonać pracę obliczania wysokości tego div
  4. ponieważ przeglądarka obsługuje rendering / rozmiar ukrytego div, unikamy jawne ustawienie textarea ' s wzrost.

document.addEventListener('DOMContentLoaded', () => {
    textArea.addEventListener('change', autosize, false)
    textArea.addEventListener('keydown', autosize, false)
    textArea.addEventListener('keyup', autosize, false)
    autosize()
}, false)

function autosize() {
    // Copy textarea contents to div browser will calculate correct height
    // of copy, which will make overall container taller, which will make
    // textarea taller.
    textCopy.innerHTML = textArea.value.replace(/\n/g, '<br/>')
}
html, body, textarea {
    font-family: sans-serif;
    font-size: 14px;
}

.textarea-container {
    position: relative;
}

.textarea-container > div, .textarea-container > textarea {
    word-wrap: break-word; /* make sure the div and the textarea wrap words in the same way */
    box-sizing: border-box;
    padding: 2px;
    width: 100%;
}

.textarea-container > textarea {
    overflow: hidden;
    position: absolute;
    height: 100%;
}

.textarea-container > div {
    padding-bottom: 1.5em; /* A bit more than one additional line of text. */ 
    visibility: hidden;
    width: 100%;
}
<div class="textarea-container">
    <textarea id="textArea"></textarea>
    <div id="textCopy"></div>
</div>
 57
Author: Jan Miksovsky,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-05-17 18:31:51

Oto kolejna technika automatyzacji obszaru tekstowego.

  • używa wysokości piksela zamiast wysokości linii: dokładniejsza obsługa zawijania linii, jeśli używana jest proporcjonalna czcionka.
  • akceptuje ID lub element jako wejście
  • akceptuje opcjonalny parametr Maksymalna wysokość - przydatny, jeśli nie chcesz, aby obszar tekstowy powiększył się o określony rozmiar (zachowaj wszystko na ekranie, unikaj łamania układu itp.)
  • Testowane na Firefoksie 3 i Internet Explorer 6

Kod: (plain vanilla JavaScript)

function FitToContent(id, maxHeight)
{
   var text = id && id.style ? id : document.getElementById(id);
   if (!text)
      return;

   /* Accounts for rows being deleted, pixel value may need adjusting */
   if (text.clientHeight == text.scrollHeight) {
      text.style.height = "30px";
   }

   var adjustedHeight = text.clientHeight;
   if (!maxHeight || maxHeight > adjustedHeight)
   {
      adjustedHeight = Math.max(text.scrollHeight, adjustedHeight);
      if (maxHeight)
         adjustedHeight = Math.min(maxHeight, adjustedHeight);
      if (adjustedHeight > text.clientHeight)
         text.style.height = adjustedHeight + "px";
   }
}

Demo: (używa jQuery, cele w textarea wpisuję teraz - jeśli masz Firebug zainstalowany, wklej oba sample do konsoli i przetestuj na tej stronie)

$("#post-text").keyup(function()
{
   FitToContent(this, document.documentElement.clientHeight)
});
 38
Author: Shog9,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:31:05

Prawdopodobnie najkrótsze rozwiązanie:

jQuery(document).ready(function(){
    jQuery("#textArea").on("keydown keyup", function(){
        this.style.height = "1px";
        this.style.height = (this.scrollHeight) + "px"; 
    });
});

W ten sposób nie potrzebujesz żadnych ukrytych div lub czegoś podobnego.

Uwaga: być może będziesz musiał grać this.style.height = (this.scrollHeight) + "px"; w zależności od tego, jak stylujesz tekstarea(wysokość linii, padding i tego typu rzeczy).

 12
Author: Eduard Luca,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:49:35

Oto prototyp Wersja zmiany rozmiaru obszaru tekstowego, który nie jest zależny od liczby kolumn w obszarze tekstowym. Jest to lepsza technika, ponieważ pozwala kontrolować obszar tekstowy za pomocą CSS, a także mieć zmienną szerokość textarea. Dodatkowo ta wersja wyświetla liczbę pozostałych znaków. Chociaż nie jest to wymagane, jest to bardzo przydatna funkcja i jest łatwo usuwana, jeśli jest niechciana.

//inspired by: http://github.com/jaz303/jquery-grab-bag/blob/63d7e445b09698272b2923cb081878fd145b5e3d/javascripts/jquery.autogrow-textarea.js
if (window.Widget == undefined) window.Widget = {}; 

Widget.Textarea = Class.create({
  initialize: function(textarea, options)
  {
    this.textarea = $(textarea);
    this.options = $H({
      'min_height' : 30,
      'max_length' : 400
    }).update(options);

    this.textarea.observe('keyup', this.refresh.bind(this));

    this._shadow = new Element('div').setStyle({
      lineHeight : this.textarea.getStyle('lineHeight'),
      fontSize : this.textarea.getStyle('fontSize'),
      fontFamily : this.textarea.getStyle('fontFamily'),
      position : 'absolute',
      top: '-10000px',
      left: '-10000px',
      width: this.textarea.getWidth() + 'px'
    });
    this.textarea.insert({ after: this._shadow });

    this._remainingCharacters = new Element('p').addClassName('remainingCharacters');
    this.textarea.insert({after: this._remainingCharacters});  
    this.refresh();  
  },

  refresh: function()
  { 
    this._shadow.update($F(this.textarea).replace(/\n/g, '<br/>'));
    this.textarea.setStyle({
      height: Math.max(parseInt(this._shadow.getHeight()) + parseInt(this.textarea.getStyle('lineHeight').replace('px', '')), this.options.get('min_height')) + 'px'
    });

    var remaining = this.options.get('max_length') - $F(this.textarea).length;
    this._remainingCharacters.update(Math.abs(remaining)  + ' characters ' + (remaining > 0 ? 'remaining' : 'over the limit'));
  }
});

Utwórz widżet wywołując new Widget.Textarea('element_id'). Domyślnymi opcjami mogą być nadpisane przez podanie ich jako obiektu, np. new Widget.Textarea('element_id', { max_length: 600, min_height: 50}). Jeśli chcesz utworzyć go dla wszystkich tekstów na stronie, zrób coś w stylu:

Event.observe(window, 'load', function() {
  $$('textarea').each(function(textarea) {
    new Widget.Textarea(textarea);
  });   
});
 8
Author: Jeremy Kauffman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-07 18:08:34

Oto rozwiązanie z JQuery:

$(document).ready(function() {
    var $abc = $("#abc");
    $abc.css("height", $abc.attr("scrollHeight"));
})

abc jest teaxtarea.

 7
Author: memical,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-23 10:29:31

Sprawdź poniższy link: http://james.padolsey.com/javascript/jquery-plugin-autoresize/

$(document).ready(function () {
    $('.ExpandableTextCSS').autoResize({
        // On resize:
        onResize: function () {
            $(this).css({ opacity: 0.8 });
        },
        // After resize:
        animateCallback: function () {
            $(this).css({ opacity: 1 });
        },
        // Quite slow animation:
        animateDuration: 300,
        // More extra space:
        extraSpace:20,
        //Textarea height limit
        limit:10
    });
});
 5
Author: Gyan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-07 18:09:04

Po prostu wracając do tego, zrobiłem to trochę uporządkowane (choć ktoś, kto jest pełna butelka na Prototype / JavaScript może sugerować ulepszenia?).

var TextAreaResize = Class.create();
TextAreaResize.prototype = {
  initialize: function(element, options) {
    element = $(element);
    this.element = element;

    this.options = Object.extend(
      {},
      options || {});

    Event.observe(this.element, 'keyup',
      this.onKeyUp.bindAsEventListener(this));
    this.onKeyUp();
  },

  onKeyUp: function() {
    // We need this variable because "this" changes in the scope of the
    // function below.
    var cols = this.element.cols;

    var linecount = 0;
    $A(this.element.value.split("\n")).each(function(l) {
      // We take long lines into account via the cols divide.
      linecount += 1 + Math.floor(l.length / cols);
    })

    this.element.rows = linecount;
  }
}

Wystarczy zadzwonić z:

new TextAreaResize('textarea_id_name_here');
 3
Author: Mike,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:33:51

Zrobiłem coś łatwego. Najpierw umieściłem TextArea w DIV. Po drugie, wywołałem funkcję ready do tego skryptu.

<div id="divTable">
  <textarea ID="txt" Rows="1" TextMode="MultiLine" />
</div>

$(document).ready(function () {
  var heightTextArea = $('#txt').height();
  var divTable = document.getElementById('divTable');
  $('#txt').attr('rows', parseInt(parseInt(divTable .style.height) / parseInt(altoFila)));
});
Proste. Jest to maksymalna wysokość div po jego wyrenderowaniu, podzielona przez wysokość jednego obszaru tekstowego jednego wiersza.
 3
Author: Eduardo Mass,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:43:33

Potrzebowałem tej funkcji dla siebie, ale żaden z nich stąd nie działał tak, jak ich potrzebowałem.

Więc użyłem kodu Oriona i zmieniłem go.

Dodałem minimalną wysokość, aby na destrukcji nie stała się zbyt mała.

function resizeIt( id, maxHeight, minHeight ) {
    var text = id && id.style ? id : document.getElementById(id);
    var str = text.value;
    var cols = text.cols;
    var linecount = 0;
    var arStr = str.split( "\n" );
    $(arStr).each(function(s) {
        linecount = linecount + 1 + Math.floor(arStr[s].length / cols); // take into account long lines
    });
    linecount++;
    linecount = Math.max(minHeight, linecount);
    linecount = Math.min(maxHeight, linecount);
    text.rows = linecount;
};
 2
Author: Peter Mortensen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:35:03

Jak odpowiedź @memical.

Znalazłem jednak pewne ulepszenia. Możesz użyć funkcji jQuery height(). Pamiętaj jednak o pikselach padding-top i padding-bottom. W przeciwnym razie textarea będzie rosnąć zbyt szybko.

$(document).ready(function() {
  $textarea = $("#my-textarea");

  // There is some diff between scrollheight and height:
  //    padding-top and padding-bottom
  var diff = $textarea.prop("scrollHeight") - $textarea.height();
  $textarea.live("keyup", function() {
    var height = $textarea.prop("scrollHeight") - diff;
    $textarea.height(height);
  });
});
 2
Author: Anatoly Mironov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:41:40

Oto rozszerzenie do prototypowego widżetu, który Jeremy opublikował 4 czerwca:

Uniemożliwia użytkownikowi wprowadzanie większej liczby znaków, jeśli używasz ograniczeń w tekstach. Sprawdza, czy zostały znaki. Jeśli użytkownik skopiuje tekst do obszaru textarea, tekst zostanie odcięty maksymalnie. długość:

/**
 * Prototype Widget: Textarea
 * Automatically resizes a textarea and displays the number of remaining chars
 * 
 * From: http://stackoverflow.com/questions/7477/autosizing-textarea
 * Inspired by: http://github.com/jaz303/jquery-grab-bag/blob/63d7e445b09698272b2923cb081878fd145b5e3d/javascripts/jquery.autogrow-textarea.js
 */
if (window.Widget == undefined) window.Widget = {}; 

Widget.Textarea = Class.create({
  initialize: function(textarea, options){
    this.textarea = $(textarea);
    this.options = $H({
      'min_height' : 30,
      'max_length' : 400
    }).update(options);

    this.textarea.observe('keyup', this.refresh.bind(this));

    this._shadow = new Element('div').setStyle({
      lineHeight : this.textarea.getStyle('lineHeight'),
      fontSize : this.textarea.getStyle('fontSize'),
      fontFamily : this.textarea.getStyle('fontFamily'),
      position : 'absolute',
      top: '-10000px',
      left: '-10000px',
      width: this.textarea.getWidth() + 'px'
    });
    this.textarea.insert({ after: this._shadow });

    this._remainingCharacters = new Element('p').addClassName('remainingCharacters');
    this.textarea.insert({after: this._remainingCharacters});  
    this.refresh();  
  },

  refresh: function(){ 
    this._shadow.update($F(this.textarea).replace(/\n/g, '<br/>'));
    this.textarea.setStyle({
      height: Math.max(parseInt(this._shadow.getHeight()) + parseInt(this.textarea.getStyle('lineHeight').replace('px', '')), this.options.get('min_height')) + 'px'
    });

    // Keep the text/character count inside the limits:
    if($F(this.textarea).length > this.options.get('max_length')){
      text = $F(this.textarea).substring(0, this.options.get('max_length'));
        this.textarea.value = text;
        return false;
    }

    var remaining = this.options.get('max_length') - $F(this.textarea).length;
    this._remainingCharacters.update(Math.abs(remaining)  + ' characters remaining'));
  }
});
 1
Author: lorem monkey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-30 14:39:24

@memical miał niesamowite rozwiązanie do ustawiania wysokości textarea na pageload z jQuery, ale dla mojej aplikacji chciałem być w stanie zwiększyć wysokość textarea jak użytkownik dodał więcej treści. Zbudowałem rozwiązanie memical z następującym:

$(document).ready(function() {
    var $textarea = $("p.body textarea");
    $textarea.css("height", ($textarea.attr("scrollHeight") + 20));
    $textarea.keyup(function(){
        var current_height = $textarea.css("height").replace("px", "")*1;
        if (current_height + 5 <= $textarea.attr("scrollHeight")) {
            $textarea.css("height", ($textarea.attr("scrollHeight") + 20));
        }
    });
});

Nie jest bardzo gładka, ale nie jest to również aplikacja skierowana do klienta, więc gładkość nie ma znaczenia. (Gdyby to było skierowane do klienta, prawdopodobnie użyłbym po prostu auto-resize jQuery plugin.)

 1
Author: Jazzerus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:34:18

Dla tych, którzy kodują dla IE i napotykają ten problem. IE ma małą sztuczkę, która sprawia, że 100% CSS.

<TEXTAREA style="overflow: visible;" cols="100" ....></TEXTAREA>

Możesz nawet podać wartość rows= "n", którą IE zignoruje, ale inne przeglądarki będą używać. Naprawdę nienawidzę kodowania, które implementuje IE hacki, ale ten jest bardzo pomocny. Możliwe, że działa tylko w trybie dziwactwa.

 1
Author: Einstein47,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-13 22:26:22

Internet Explorer, Safari, Chrome i Opera użytkownicy muszą pamiętać o wyraźnym ustawieniu wartości line-height w CSS. Wykonuję arkusz stylów, który ustawia początkowe właściwości dla wszystkich pól tekstowych w następujący sposób.

<style>
    TEXTAREA { line-height: 14px; font-size: 12px; font-family: arial }
</style>
 1
Author: Larry,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:37:44

Oto funkcja, którą napisałem w jQuery, aby to zrobić - możesz ją przenieść do Prototype , ale nie obsługują one "żywotności" jQuery, więc elementy dodane przez żądania Ajax nie będą odpowiadać.

Ta wersja nie tylko rozszerza się, ale także kontraktuje się po naciśnięciu delete lub backspace.

Ta wersja opiera się na jQuery 1.4.2.

Enjoy;)

Http://pastebin.com/SUKeBtnx

Użycie:

$("#sometextarea").textareacontrol();

Lub (dowolny selektor jQuery dla przykład)

$("textarea").textareacontrol();

Został przetestowany na Internet Explorer 7/Internet Explorer 8 , Firefox 3.5 i Chrome. Wszystko działa dobrze.

 1
Author: Alex,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:40:11

Za pomocą ASP.NET, po prostu zrób to:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Automatic Resize TextBox</title>
        <script type="text/javascript">
            function setHeight(txtarea) {
                txtarea.style.height = txtdesc.scrollHeight + "px";
            }
        </script>
    </head>

    <body>
        <form id="form1" runat="server">
            <asp:TextBox ID="txtarea" runat= "server" TextMode="MultiLine"  onkeyup="setHeight(this);" onkeydown="setHeight(this);" />
        </form>
    </body>
</html>
 1
Author: Pat Murray,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:45:29

Moje rozwiązanie nie używające jQuery (bo czasami nie muszą być takie same) jest poniżej. Chociaż został przetestowany tylko w Internet Explorer 7 , więc społeczność może wskazać wszystkie przyczyny tego błędu:

textarea.onkeyup = function () { this.style.height = this.scrollHeight + 'px'; }

Jak na razie bardzo mi się podoba jak to działa i nie obchodzą mnie inne przeglądarki, więc pewnie zastosuję to do wszystkich moich tekstowych:

// Make all textareas auto-resize vertically
var textareas = document.getElementsByTagName('textarea');

for (i = 0; i<textareas.length; i++)
{
    // Retain textarea's starting height as its minimum height
    textareas[i].minHeight = textareas[i].offsetHeight;

    textareas[i].onkeyup = function () {
        this.style.height = Math.max(this.scrollHeight, this.minHeight) + 'px';
    }
    textareas[i].onkeyup(); // Trigger once to set initial height
}
 1
Author: user1566694,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-13 00:48:10