I confess I don't really have any knowledge of Javascript. I found this on the internet and it does do what I want:
<script type="text/javascript">
function CopyToClipboard(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select().createTextRange();
document.execCommand("copy");
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
document.execCommand("copy");
alert("The assignment slip has been copied, now paste into an email")
}
}
</script>
It is called like this:
<button id="button1" onclick="CopyToClipboard('containter-student-slip1')">Click to copy</button>
The problem is that I must clear the selection before I click the next button in the browser. I would like it to simply select the specified element with ID and replace any existign selection in the browser.