Copy to clipboard from multiple HTML elements using javascript











up vote
0
down vote

favorite












enter image description here



In the above image , when I click on Add person, Person 2 row gets created and so on. I have a copy icon for each row. Now when I click on an icon, I am trying to copy the user entered text from the input field and the text displayed in another text area (Hi! You entered). I have created a text area element to store the copied text ( texts from both input field and text area). But I am facing the below issues.




  1. The newly created textarea element occupies space which I don't want to happen. If I hide the element , then copy to clipboard functionality doesn't work. How to achieve this?


  2. If I enter 1 in the input field for Person 1 , 2 in Person 2 input field , on click of copy from person 1 , it pastes Hi! You entered 2, but that is wrong, because I am binding the user entered input value to the newly created text area element which is not as expected. Ideally , it should copy the text for that particular row and binding it to the dummy text area. How to achieve this?



    <div>
    <textarea>Hi! You entered</textarea>
    <textarea #resultField>Hi! You entered {{resultamount}</textarea>//This is the newly created element to combine the above text and user entered input from input field
    </div>

    <div>
    <input #enteramount (input)="getamountValue(enteramount)">
    <a (click)="copyInputMessage(resultField)">{{'copyMsg' | translate}}</a>
    </div>

    ngOnInit() {
    this.persons = [
    { 'name': 'Person 1' }
    ];
    }

    getamountValue(inputAmount) {
    this.resultamount = inputAmount.value;
    }

    copyInputMessage(outputField){
    outputField.select();
    document.execCommand('copy');
    outputField.setSelectionRange(0, 0);
    }

    //function called on click of Add New button to add consecutive rows of Person
    addNewRow() {
    this.persons.push({ 'name': 'Person ' + (this.persons.length + 1) });
    }











share|improve this question









New contributor




Jessy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote

    favorite












    enter image description here



    In the above image , when I click on Add person, Person 2 row gets created and so on. I have a copy icon for each row. Now when I click on an icon, I am trying to copy the user entered text from the input field and the text displayed in another text area (Hi! You entered). I have created a text area element to store the copied text ( texts from both input field and text area). But I am facing the below issues.




    1. The newly created textarea element occupies space which I don't want to happen. If I hide the element , then copy to clipboard functionality doesn't work. How to achieve this?


    2. If I enter 1 in the input field for Person 1 , 2 in Person 2 input field , on click of copy from person 1 , it pastes Hi! You entered 2, but that is wrong, because I am binding the user entered input value to the newly created text area element which is not as expected. Ideally , it should copy the text for that particular row and binding it to the dummy text area. How to achieve this?



      <div>
      <textarea>Hi! You entered</textarea>
      <textarea #resultField>Hi! You entered {{resultamount}</textarea>//This is the newly created element to combine the above text and user entered input from input field
      </div>

      <div>
      <input #enteramount (input)="getamountValue(enteramount)">
      <a (click)="copyInputMessage(resultField)">{{'copyMsg' | translate}}</a>
      </div>

      ngOnInit() {
      this.persons = [
      { 'name': 'Person 1' }
      ];
      }

      getamountValue(inputAmount) {
      this.resultamount = inputAmount.value;
      }

      copyInputMessage(outputField){
      outputField.select();
      document.execCommand('copy');
      outputField.setSelectionRange(0, 0);
      }

      //function called on click of Add New button to add consecutive rows of Person
      addNewRow() {
      this.persons.push({ 'name': 'Person ' + (this.persons.length + 1) });
      }











    share|improve this question









    New contributor




    Jessy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      enter image description here



      In the above image , when I click on Add person, Person 2 row gets created and so on. I have a copy icon for each row. Now when I click on an icon, I am trying to copy the user entered text from the input field and the text displayed in another text area (Hi! You entered). I have created a text area element to store the copied text ( texts from both input field and text area). But I am facing the below issues.




      1. The newly created textarea element occupies space which I don't want to happen. If I hide the element , then copy to clipboard functionality doesn't work. How to achieve this?


      2. If I enter 1 in the input field for Person 1 , 2 in Person 2 input field , on click of copy from person 1 , it pastes Hi! You entered 2, but that is wrong, because I am binding the user entered input value to the newly created text area element which is not as expected. Ideally , it should copy the text for that particular row and binding it to the dummy text area. How to achieve this?



        <div>
        <textarea>Hi! You entered</textarea>
        <textarea #resultField>Hi! You entered {{resultamount}</textarea>//This is the newly created element to combine the above text and user entered input from input field
        </div>

        <div>
        <input #enteramount (input)="getamountValue(enteramount)">
        <a (click)="copyInputMessage(resultField)">{{'copyMsg' | translate}}</a>
        </div>

        ngOnInit() {
        this.persons = [
        { 'name': 'Person 1' }
        ];
        }

        getamountValue(inputAmount) {
        this.resultamount = inputAmount.value;
        }

        copyInputMessage(outputField){
        outputField.select();
        document.execCommand('copy');
        outputField.setSelectionRange(0, 0);
        }

        //function called on click of Add New button to add consecutive rows of Person
        addNewRow() {
        this.persons.push({ 'name': 'Person ' + (this.persons.length + 1) });
        }











      share|improve this question









      New contributor




      Jessy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      enter image description here



      In the above image , when I click on Add person, Person 2 row gets created and so on. I have a copy icon for each row. Now when I click on an icon, I am trying to copy the user entered text from the input field and the text displayed in another text area (Hi! You entered). I have created a text area element to store the copied text ( texts from both input field and text area). But I am facing the below issues.




      1. The newly created textarea element occupies space which I don't want to happen. If I hide the element , then copy to clipboard functionality doesn't work. How to achieve this?


      2. If I enter 1 in the input field for Person 1 , 2 in Person 2 input field , on click of copy from person 1 , it pastes Hi! You entered 2, but that is wrong, because I am binding the user entered input value to the newly created text area element which is not as expected. Ideally , it should copy the text for that particular row and binding it to the dummy text area. How to achieve this?



        <div>
        <textarea>Hi! You entered</textarea>
        <textarea #resultField>Hi! You entered {{resultamount}</textarea>//This is the newly created element to combine the above text and user entered input from input field
        </div>

        <div>
        <input #enteramount (input)="getamountValue(enteramount)">
        <a (click)="copyInputMessage(resultField)">{{'copyMsg' | translate}}</a>
        </div>

        ngOnInit() {
        this.persons = [
        { 'name': 'Person 1' }
        ];
        }

        getamountValue(inputAmount) {
        this.resultamount = inputAmount.value;
        }

        copyInputMessage(outputField){
        outputField.select();
        document.execCommand('copy');
        outputField.setSelectionRange(0, 0);
        }

        //function called on click of Add New button to add consecutive rows of Person
        addNewRow() {
        this.persons.push({ 'name': 'Person ' + (this.persons.length + 1) });
        }








      javascript angular copy clipboard paste






      share|improve this question









      New contributor




      Jessy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Jessy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 14 hours ago









      kit

      758116




      758116






      New contributor




      Jessy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 15 hours ago









      Jessy

      12




      12




      New contributor




      Jessy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Jessy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Jessy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Jessy is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407876%2fcopy-to-clipboard-from-multiple-html-elements-using-javascript%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Jessy is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          Jessy is a new contributor. Be nice, and check out our Code of Conduct.













          Jessy is a new contributor. Be nice, and check out our Code of Conduct.












          Jessy is a new contributor. Be nice, and check out our Code of Conduct.















           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407876%2fcopy-to-clipboard-from-multiple-html-elements-using-javascript%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Futebolista

          Jornalista