Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy textarea text to clipboard html / javascript

hey, i know there's lots of tutorials out there but none seem to be working for me.

I have this :

<textarea name="forum_link" type="text" style="width:630px; height:90px;">
[URL=http://www.site.net/video/<?=$_GET['id']?>/<?=$_GET['tag']?>]<?=$video->title?>[/URL]

[URL=http://www.site.net/video/<?=$_GET['id']?>/<?=$_GET['tag']?>][IMG]<?=$video->thumbnailURL?>[/IMG][/URL]
</textarea>

Now all i want is a simple button, that when clicked copies the text in the textarea to the users clipboard.

Any help would be great :)

Thanks

like image 818
Belgin Fish Avatar asked Jul 03 '26 03:07

Belgin Fish


1 Answers

<textarea id="html" name="html">Some text</textarea>
<input type="button" value="Refresh" onclick="copy_to_clipboard('html');">

<script>
function copy_to_clipboard(id)
{
    document.getElementById(id).select();
    document.execCommand('copy');
}
</script>
like image 52
MeKoo Solutions Avatar answered Jul 05 '26 18:07

MeKoo Solutions