1

When we paste data in input field, we can not fetch data from input field, it's always show blank;

function myFunction() {
      console.log(document.getElementById("inpt").innerText);
      document.getElementById("demo").innerHTML = document.getElementById("inpt").innerText;
}
<input id="inpt"  type="text" onpaste="myFunction()" value="Try to paste something in here" size="40">
    
<p id="demo"></p>
Mustapha Larhrouch
  • 3,373
  • 3
  • 14
  • 28
Ayush Sahu
  • 268
  • 3
  • 15

2 Answers2

0

For Angular, try this:

Template:

<input id="inpt"  type="text" (paste)="myFunction($event)" value="Try to paste something in here" size="40">

TS:

myFunction(event: ClipboardEvent) {
      let clipboardData = event.clipboardData || window.clipboardData;
      let pastedText = clipboardData.getData('text');
      console.log(pastedText);
}
Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79
0

You need to add setTimeout function for that.

function myFunction() {
    setTimeout(function(){
        document.getElementById("demo").innerHTML = document.getElementById('inpt').value;
    })
}
<input id="inpt"  type="text" onpaste="myFunction()" value="abc abc" size="40">
    
<p id="demo"></p>
Chintan Kotadiya
  • 1,335
  • 1
  • 11
  • 19