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,279
  • 2
  • 11
  • 27
Ayush Sahu
  • 258
  • 2
  • 14

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
  • 17,967
  • 8
  • 40
  • 61
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,182
  • 1
  • 10
  • 17