cleary1981 Posted July 11, 2008 Share Posted July 11, 2008 Hi, I have added in a drag and drop function from a tutorial and it works well. The problem I am having is that I need my variable g_objName to be associated with dragobj. Has anyone any ideas? function showObject (){ if (request.readyState == 4) { var returned = request.responseText; var splitResult = returned.split(" "); var h = splitResult[0]; var w = splitResult[1]; h = h/5; w = w/5; cv = document.getElementById("canvas"); var newObject = document.createElement('div'); newObject.Class = g_objName; newObject.id = "newObject"; newObject.innerHTML = g_objName; newObject.style.height = h; newObject.style.width = w; newObject.onmousedown=function(){grab(this);} cv.appendChild(newObject); } function grab(context) { document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection dragobj = context; dragobj.style.zIndex = 10; // move it to the top document.onmousemove = drag; document.onmouseup = drop; grabx = mousex; graby = mousey; elex = orix = dragobj.offsetLeft; eley = oriy = dragobj.offsetTop; update(); } Quote Link to comment Share on other sites More sharing options...
vikramjeet.singla Posted July 11, 2008 Share Posted July 11, 2008 can you paste all of your html page here.... Quote Link to comment Share on other sites More sharing options...
cleary1981 Posted July 11, 2008 Author Share Posted July 11, 2008 it isn't needed to solve this. I simply want to pass the variable from the first function to the second Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted July 11, 2008 Share Posted July 11, 2008 Hi, I have added in a drag and drop function from a tutorial and it works well. The problem I am having is that I need my variable g_objName to be associated with dragobj. Has anyone any ideas? function showObject (){ if (request.readyState == 4) { var returned = request.responseText; var splitResult = returned.split(" "); var h = splitResult[0]; var w = splitResult[1]; h = h/5; w = w/5; cv = document.getElementById("canvas"); var newObject = document.createElement('div'); newObject.Class = g_objName; newObject.id = "newObject"; newObject.innerHTML = g_objName; newObject.style.height = h; newObject.style.width = w; newObject.onmousedown=function(){grab(this);} cv.appendChild(newObject); } function grab(context) { document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection dragobj = context; dragobj.style.zIndex = 10; // move it to the top document.onmousemove = drag; document.onmouseup = drop; grabx = mousex; graby = mousey; elex = orix = dragobj.offsetLeft; eley = oriy = dragobj.offsetTop; update(); } Hmm... wouldn't g_objName already be available to you in grab()? You're assigning the function to the onmousedown event handler of newObject. Since g_objName is a property of newObject, it should be available inside of grab() as this.g_objName. Quote Link to comment Share on other sites More sharing options...
cleary1981 Posted July 11, 2008 Author Share Posted July 11, 2008 Doh.. why didnt i see that. lol Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.