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(); } Link to comment https://forums.phpfreaks.com/topic/114243-solved-passing-a-variable/ 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.... Link to comment https://forums.phpfreaks.com/topic/114243-solved-passing-a-variable/#findComment-587441 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 Link to comment https://forums.phpfreaks.com/topic/114243-solved-passing-a-variable/#findComment-587449 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. Link to comment https://forums.phpfreaks.com/topic/114243-solved-passing-a-variable/#findComment-587456 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 Link to comment https://forums.phpfreaks.com/topic/114243-solved-passing-a-variable/#findComment-587463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.