help with drag and drop in javascript

+1 prajakta kavthekar · November 29, 2014
function dofirst(){
mypic.document.getElementById('picture');
mypic.addEventListener("dragstart",startDrag,false);
leftbox=document.getElementById('leftbox');
leftbox=addEventListener("dragenter", function(e){e.preventDefault();} ,false);
leftbox=addEventListener("dragover",function(e){e.preventDefault();} ,false);
leftbox=addEventListener("drop", dropped ,false);

}
function startDrag(e){
var code='<img id="picture" src="monsters_inc.jpg" >';
e.dataTransfer.setData('Text',code);
}
function dropped(e){
e.preventDefault();
leftbox.innerHTML = e.dataTransfer.getData('Text');
}

window.addEventListener('load',dofirst,false);



here is my javascript code...
couldnot drag and drop.. i cannot find what i a doing wrong... please help

Post a Reply

Replies

Oldest  Newest  Rating
0 parkhar Sharma · July 3, 2015
Prajakta there are a lot of errors ,most of them silly ones .

here is the edited version of your code ,try running this .

function doFirst(){
mypic=document.getElementById('picture');
mypic.addEventListener("dragstart",startDrag,false);
leftbox=document.getElementById('leftbox');
leftbox.addEventListener("dragenter", function(e){e.preventDefault();} ,false);
leftbox.addEventListener("dragover",function(e){e.preventDefault();} ,false);
leftbox.addEventListener("drop", dropped ,false);

}
function startDrag(e){
var code='<img id="picture" src="monsters_inc.jpg" >';
e.dataTransfer.setData('Text',code);
}
function dropped(e){
e.preventDefault();
leftbox.innerHTML = e.dataTransfer.getData('Text');
}

window.addEventListener("load",doFirst, false);
0 Muhammad Younus · January 6, 2015
same problem
  • 1

HTML / CSS / Web Design

107,220 followers
About

Discuss, share, ask, learn and teach HTML5 and CSS3.

Links
Moderators