Answer the question
In order to leave comments, you need to log in
How to drag DND text to input?
There is this code:
print "<a draggable='true' ondragstart='drag(event)'>Hello</a>";
print "<br><input id=data type=text name=p1 ondrop='drop(event)' ondragover='allowDrop(event)'>"
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData('text', ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData('text');
ev.target.appendChild(document.getElementById(data));
}
</script>
Answer the question
In order to leave comments, you need to log in
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData('text');
var elem = document.getElementById(data)
ev.target.appendChild(elem);
}
I already solved this problem myself. Thanks to everyone for the help)
I leave the code here just in case.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question