JavaScript

Button event select the text from textarea in Javascript

Button event select the text from textarea in Javascript, someone asked me to explain?

In this example I will show you how to select text from textarea in javascript. We can select the entire contents of text area using select property. 

Example:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Language" content="en-us" />
    <title>select the text from textarea in Javascript</title>
    <style type="text/css">
        .btn {
            width: 100px;
            height: 50px;
            background: #00BCD4;
            border-style: solid;
            border-color: white;
            color: white;
        }
    </style>
    <script type="text/javascript">
        function OnSelectCode() {
            document.getElementById("code").select();
        }
 
     </script>
</head>
<body style="width: 500px;">
    <h1>select the text from textarea in Javascript</h1>
    <table>
        <tr>
            <td colspan="3" style="color: darkblue;">click on the button to select the text from textarea</td>
        </tr>
        <tr>
            <td colspan="3">
                <textarea rows="15" style="width: 400px" id="code">
Linq is very easy to read and simplifies the code. We can filter and List the group of words by string length from a string array.
</textarea></td>
        </tr>
        <tr>
            <td colspan="3">
                <input type="button" value="Select Code" class="btn" onclick="OnSelectCode()"></td>
        </tr>
    </table>
</body>
</html>

Output:

select the text from textarea in Javascript

Post your comments / questions