Copy to clipboard from two HTML elements

2019-01-29 10:33发布

问题:

I have the below code with two HTML elements, one is text area which has a value , You entered and the other one is a input element in which user enters the amount as ( say 100 INR ) . When I click on the anchor link , copyInputMessage method gets called and i am trying to copy the text area value and paste somewhere. It now pastes 'You entered' text in notepad. The issue here is I need to copy both You entered and user entered amount value and paste to notepad, like , "You entered 100 INR"

<textarea id="textarea1" #userinput > You entered </textarea>

       <input id="form5" class="form-control" #enteramount type="text">

     <li class="copy-message">
                      <a (click)="copyInputMessage(userinput)">Copy message</a>
                    </li>

    copyInputMessage(inputElement){
        inputElement.select(); // selecting only textarea value
        document.execCommand('copy');
        inputElement.setSelectionRange(0, 0); //pastes only textarea value
      }