0

I want to copy a input text to a clipboard and add before a string. I use

function copyLastColumn() {
  var copyText = document.getElementById("oidinput");
  copyText.select();
  document.execCommand("copy");
}

I want to add the string "DDE-" before the copytext. HOw can I do it? Thanks Sven

1 Answers1

0

What I did here was to set the value of the input (i.e. the text) to your prefix "DDE-" + original text, copy it, and then return the input to the original text.

function copyLastColumn() {
  let input = document.getElementById("oidinput");
  let originalText = input.value;
  input.value = "DDE-" + originalText;
  input.select();
  document.execCommand('copy');
  input.value = originalText;
}
<body><input type="text" id="oidinput" />
  <button onclick="copyLastColumn()">copy</button>
</body>
Omri Attiya
  • 3,917
  • 3
  • 19
  • 35