Javascript Form How to - Select the text in TextArea








Question

We would like to know how to select the text in TextArea.

Answer


   <!--from w w  w.ja v a 2s .c  o m-->
    
<html>
<body>
<script language="JavaScript">
    function function2() {
        document.all.myTextArea.select();
    }
</script>
<textarea id=myTextArea>Some text</textarea>
<input type="button" value='Select the textarea' onclick="function2()">
</body>
</html>

The code above is rendered as follows: