Auto expand textarea is a normal requirement for web forms in community based web applications.A number of solutions are available for this with jquery and javascript. But here is a solution that can perfectly work in any html page, no jquery needed. Just a few lines of code is enough. Try this out !
1) Add the following javascript function before closing your </head> tag in html page
<script>
function textAreaAdjust(o) {
o.style.height = "1px";
o.style.height = (25+o.scrollHeight)+"px";
}
</script>
2) Call the above function in onkeyup for your text area.
<textarea onkeyup="textAreaAdjust(this)" style="overflow:hidden"></textarea>
3) Now execute your file from browser URL. You can see that the text area expanding with content.
You can download the source code here.
If you have any questions, please feel free to email us at support@innovativewebz.com
No comments:
Post a Comment