JAVASCRIPT

HOW TO COPY CUT PASTE IN JAVASCRIPT

GET VALUE FROM FIELD var txt = document.getElementById ("FIELD").value;

COPY FROM FIELD

01

OPTIONAL - DO THIS AFTER COPY then(() => { alert("Copied"); });

PUT TEXT INTO CLIPBOARD navigator.clipboard.writeText(txt)

GET TEXT FROM ELEMENT var txt = document.getElementById ("TARGET").innerText;

COPY FROM HTML ELEMENT

02

OPTIONAL - DO THIS AFTER COPY .then(() => { alert("Copied"); });

PUT TEXT INTO CLIPBOARD navigator.clipboard.writeText(txt)

CUT FROM FIELD

03

GET VALUE FROM FIELD var txt = document.getElementById ("FIELD").value;

EMPTY FIELD AFTER COPY .then(() => { document.getElementById ("TARGET").value = ""; });

PUT TEXT INTO CLIPBOARD navigator.clipboard.writeText(txt)

PASTE INTO FIELD

04

READ FROM CLIPBOARD - PERMISSION REQUIRED navigator.clipboard.readText()

PUT CLIPBOARD INTO TEXT FIELD .then(txt => {   document.getElementById("INPUT")   .value = txt; })

CANNOT ACCESS CLIPBOARD .catch(err => { alert("ERROR"); });