Onclick Select All and Copy to Clipboard (javascript)

javascript clipboard

In sometimes, in html , if you want to select the text for a textbox or a textarea , you can use the following script

<script type=”text/javascript”>

function select_all(obj)

{ var text_val=eval(obj);



if (!document.all) return; // IE only

r= text_val.createTextRange();


} </script>
The html part is:

<input value=”http://www.sajithmr.com” onclick=”select_all(this)” name=”url” type=”text” />The above script will select all the text for input field and copy to clipboard (for IE only)

45 thoughts on “Onclick Select All and Copy to Clipboard (javascript)

Leave a Reply