Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Expanding text area question about this code

    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.


    Code:
    <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.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,676
    Thanks
    25
    Thanked 653 Times in 652 Posts
    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.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by sunfighter View Post
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •