Is it possible to resize a text input box as text is typed? I've searched the web and haven't found anything.
I just made one for you, try it here: http://jsfiddle.net/FNMSP/2/
function autoResize(e){
var ele=e.target; //get the text field
var t=ele.scrollTop; //use scroll top to determine if
ele.scrollTop=0 //space is enough
if(t>0){ //If it needs more space....
ele.style.height=(ele.offsetHeight+t+t)+"px"; //Then add space for it!
}
}
You can do this to the textarea,
<textarea onkeydown="autoResize(event)">Auto Resize!</textarea>
Or use below to attach the function to every <textarea>
:
var ele=document.getElementsByTagName("textarea");
for(i=0;i<ele;i++){
ele[i].addEventListener("keydown",autoResize,false)
}
Feel free to use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With