How do I automatically select the text that is in a textarea when the page loads using JavaScript?
JSFiddle Demo
You can do it this way:
HTML:
<textarea id='mytext'>Testing 1 2 3</textarea>
JavaScript:
window.onload = document.getElementById('mytext').select();
Where mytext is your textarea
Try this:
Textarea:
<textarea rows="3" id="txtarea" style="width:200px" >This text you can select all by clicking here </textarea>
<script type="text/javascript">
document.getElementById('txtarea').focus();
document.getElementById('txtarea').select();
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With