Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript textarea autosize

function addAutoResize() {
  document.querySelectorAll('[data-autoresize]').forEach(function (element) {
    element.style.boxSizing = 'border-box';
    var offset = element.offsetHeight - element.clientHeight;
    element.addEventListener('input', function (event) {
      event.target.style.height = 'auto';
      event.target.style.height = event.target.scrollHeight + offset + 'px';
    });
    element.removeAttribute('data-autoresize');
  });
}
Comment

autosize a textarea using Prototype

<!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("
")).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>
Comment

PREVIOUS NEXT
Code Example
Javascript :: Destructing variable assignment 
Javascript :: 1521334061 
Javascript :: Grunt--project configuration object--uglify 
Javascript :: Cannot GET / 
Javascript :: angular dynamic script loading 
Javascript :: skipping test suites chai 
Javascript :: de-encrpting data in javascript 
Javascript :: queen of spain 
Javascript :: how to print date in javascript without time 
Javascript :: typeerror: chogigabsi eobnun bin beyole dehan recudenun error. 
Javascript :: node.js workflow template 
Javascript :: js get word before question mark 
Javascript :: como pegar o texto dentro do imput js 
Javascript :: Nodemon e criando o Servidor com express 
Javascript :: libfluidsynth npm 
Javascript :: open screen pdf on google drive react native expo 
Javascript :: react auto import sometime not working 
Javascript :: javascript intl.datetimeformat brasil 
Javascript :: radio button enable and requerd in jquery 
Javascript :: turn gravity off on one object matter js 
Javascript :: canvas circle blurry 
Javascript :: node mongodb select collection 
Javascript :: how 2 stop gif loop jsx 
Javascript :: parent child to json tree python 
Javascript :: zgadfgad 
Javascript :: Get cheapest price phone from an object in javascript 
Javascript :: add codegrepper 
Javascript :: how to ask a question in a popup javascript 
Javascript :: javascript onclick parameters 
Javascript :: javascript list all declared variables 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =