PDA

View Full Version : Expanding text area question about this code



SpidersWebHelp
Mar 28th, 2014, 01:56 PM
Hi All,

I have seen many and various suggested codes for expanding text areas in forms and my question relates to a simple code I wrote which uses none of the sometime complex coding to expand and shrink the text area. It is shown below.

This seems to work in IE, FF and Chrome and I am wondering is it actually a valid code for the purpose of expanding text areas, or is it just luck it functioned.




<script>
function Comment_resizeIt()
{
if (document.getElementById('Comment_textarea').scrollHeight > 50){var whatscrollheight = document.getElementById("Comment_textarea").scrollHeight;document.getElementById("Comment_textarea").style.height=whatscrollheight;}
}
</script>

<style type="text/css">
textarea{
width: 512px;
height: 50px;
border: 1px solid #464646;
font-family: arial;
font-size: 14px;
padding: 5px;
color:#464646;
}
body{
overflow:hidden;
}
</style>

<BR><BR>

<textarea id="Comment_textarea" style="overflow:hidden;" onkeyup="Comment_resizeIt()"></textarea>




Martin.

sunfighter
Mar 28th, 2014, 10:54 PM
If your using HTML5, and it looks like you are, then a resize handle is standard for the textarea in all moderen browsers. No JS needed.

felgall
Mar 29th, 2014, 12:24 AM
If your using HTML5, and it looks like you are, then a resize handle is standard for the textarea in all moderen browsers. No JS needed.

You don't even need to be using HTML 5. The resize handle is there for all web pages as it is built into all modern browsers.