Copy field value with button to clipboard

Hi There,

I have users that would like to copy the content of a field to their clipboard to use in another application.

Therefore i want to place a button next to that field (or create a new field with a button in it) with some code to get this done. is their anyone who can give me an example or explanation how to do this.

You need to create a text field with the Label Field set to ON

in onLoad assign it the following value
{copybutton} = “<button type=\“button\” onclick=\“CopyToClipBoard(‘Your field ID’)\” >Copy</button>”;

finally in onScriptInit
?>
<script>
function CopyToClipBoard(FieldID)
{
var sText = document.getElementById(FieldID);
sText.select();
sText.setSelectionRange(0, 99999);
document.execCommand(“copy”);
}
</script>
<?php

1 Like

thanks very much, i tried such a code but this code and the other one somehow doesn’t work in my application.

Somehow it didn’t get triggered. The FieldID isn’t the same as the field name is it? The field id on every record is not the same eg id_field_name_1 - id_field_name_2

i tried also the field name (fieldname} with or without brackets, nothing seems to trigger it.
Also

This will work for field in a form

Use inspect function of your browser to find your javascript ID

Normally the ID for a field will be id_sc_field_name_1

Well that did something it copied the Field1 the lookup was the one i tried before but now with the adoption it copies.

but… it only made a copy of the first record (that’s normal because the id referred to the first one) … mhmmm

The ID you should use is one of the 3 inside the span

id_lookup_klascode_1
id_read_off_klascode_1
id_read_on_klascode_1

Also replace

sText.select();
sText.setSelectionRange(0, 99999);
document.execCommand(“copy”);

by

var textArea = document.createElement("textarea");
textArea.value = sText.textContent;
document.body.appendChild(textArea);
textArea.select();
document.execCommand("Copy");
textArea.remove();

This should work

That did for most part the trick the field id is called id_lookup_klascode_1

but this i got working with the previous script. not as neat as this one. thanks again for support. The trick is to get this working in a multirecord form. now the id id_lookup_klascode_1 always refers to the first record… mhmmm