Autosize A Textarea Using Prototype

[Solved] Autosize A Textarea Using Prototype | Vb - Code Explorer | yomemimo.com
Question : javascript textarea autosize

Answered by : good-gnat-rkk0y17plg85

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'); });
}

Source : https://stephanwagner.me/auto-resizing-textarea-with-vanilla-javascript | Last Update : Wed, 20 Apr 22

Question : autosize a textarea using Prototype

Answered by : bulbul-ahmed

<!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>

Source : https://stackoverflow.com/questions/7477/how-to-autosize-a-textarea-using-prototype | Last Update : Sat, 31 Jul 21

Answers related to autosize a textarea using prototype

Code Explorer Popular Question For Vb