Answer the question
In order to leave comments, you need to log in
Why is text not being written to a variable from the buffer when it is pasted on the phone?
There is this:
> Example on jsfiddle
HTML :
<input type="text" maxlength="0" placeholder="Paste your text">
<textarea id="txt" disabled></textarea>
body {text-align: center;}
input[type=text] {
display: block;
margin: 30px auto;
border: 1px dashed #3d3d3d;
text-align: center;
outline: none;
}
textarea {
position: relative;
width: 250px;
outline: none;
resize: none;
margin-left: -5px;
}
document.querySelector("input").addEventListener("paste", function(e) {
alert("Thanks")
e.preventDefault();
var pastetext = e.clipboardData.getData("text/plain");
document.getElementById('txt').value = pastetext;
});
Answer the question
In order to leave comments, you need to log in
Most likely you don't have access to clipboardData
. But there is a workaround - the content of the clipboard is in the input. And maxlength must be removed.
Full code:
HTML
<input id="txt2" type="text" placeholder="Paste your text">
<textarea id="txt" disabled></textarea>
document.querySelector("#txt2").addEventListener("paste", function(e) {
alert("Thanks")
e.preventDefault();
var pastetext = e.clipboardData.getData("text/plain");
document.getElementById('txt').value = document.getElementById('txt2').value;
});
document.querySelector("#txt2").addEventListener("change", function() {
document.getElementById('txt2').value = '';
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question