0

I have this content Drag and drop script which i use to submit some values to a php page when performed. It works like charm on system but when i open the page in mobile, it does get dragged.

the code goes as::

<html>
<head>
<script>
/* Event fired on the drag target */
function dragStart(event) {
  event.dataTransfer.setData("Text", event.target.id);   
}

/* Events fired on the drop target */
function allowDrop(event) {
  event.preventDefault();
}

function drop(event) {
  event.preventDefault();
  var data = event.dataTransfer.getData("Text");
  event.target.appendChild(document.getElementById(data));
  document.getElementById("submit").submit();
}
</script>
</head>
<body>
<form action="page1.php" method="post" id="submit"></form>

<ul class="link">                       
     <li ondragstart="dragStart(event)" draggable="true" id="dragtarget">500/</li>
</ul>

<div class="rect2" ondrop="drop(event)" ondragover="allowDrop(event)">
     <span class="amnt"> value here </span>
</div>

</body>
</html>

now it works perfectly fine in computer but it doesn't get dragged in mobile version...\

Cœur
  • 37,241
  • 25
  • 195
  • 267
harishk
  • 418
  • 5
  • 21
  • Possible duplicate of [html5 drag and drop FOR MOBILE](http://stackoverflow.com/questions/20927759/html5-drag-and-drop-for-mobile) – Shota Feb 18 '17 at 11:34

1 Answers1

1

By default you are supposed to use the touch events instead.

However it seems that if you include this shim you can get drag & drop events to also work on mobile with no modifications to your code.

Bemmu
  • 17,849
  • 16
  • 76
  • 93
  • so, if i just make new js of that code and include it in my html, it will do? – harishk Feb 18 '17 at 11:47
  • I tried it with your code and it seemed to work by just including that script. – Bemmu Feb 18 '17 at 11:49
  • the solution works but, it came with a problem like, i have multiple images in the same page, which have links to them for another pages, but after adding this script, the links on the images are not working.. can you check on that one,... – harishk Feb 18 '17 at 12:23