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);

text_val.focus();

text_val.select();

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

r= text_val.createTextRange();

r.execCommand(\’copy\’);

} </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