Advertisement
deadhead1971

Click to copy text from an input field, from a loop

Jul 30th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. Using Toolset, displaying a View with a loop.
  2.  
  3. HTML example:
  4. <input type="text" value="[types field='code'][/types]" id="DiscountCode-[types field='promotion-id' output='raw'][/types]">
  5. <button onclick="myFunction('DiscountCode-[types field='promotion-id' output='raw'][/types]')">Copy text</button>
  6.  
  7. JS:
  8.  
  9. function myFunction(textid) {
  10. /* Get the text field */
  11. var copyText = document.getElementById(textid);
  12.  
  13. /* Select the text field */
  14. copyText.select();
  15.  
  16. /* Copy the text inside the text field */
  17. document.execCommand("copy");
  18.  
  19. /* Alert the copied text */
  20. alert("Copied the text: " + copyText.value);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement