cleary1981 Posted July 30, 2008 Share Posted July 30, 2008 Hi I'm having a problem trying to delete an object in javascript. Heres the code I used to create it. function showObject (){ if (request.readyState == 4) { var returned = request.responseText; var splitResult = returned.split(" "); var h = splitResult[0]; var w = splitResult[1]; // the dimensions must be set to a scale as they are to big for the screen. 25px represents 100mm h = h/5; w = w/5; cv = document.getElementById("canvas"); newObject = document.createElement('div'); newObject.Class = g_objName; newObject.id = "newObject"; newObject.innerHTML = g_objName; newObject.alt = g_objName; newObject.style.height = h; newObject.style.width = w; newObject.onmousedown=function(){grab(this);} cv.appendChild(newObject); } } heres what I have so far on the delete function function obj_delete() { var obj_name = document.getElementById("object").value; var proj_id = document.getElementById("projID").value; var url = "deleteObject.php?obj_name=" + escape(obj_name) + "&proj_id=" + escape(proj_id); request.open("GET", url, true); request.send(null); delete canvas.Child; } As you can see from my code I have deleted the object in my db ok but I need to be able to delete the object on the webpage. newObject where its innerHTML = var obj_name in the delete function. Any help much appreciated. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 31, 2008 Share Posted July 31, 2008 The way I see it you are trying to remove an element with an id of "object" and the element you created was "newObject." Anyway, since you used appendChild() to put the object somewhere, you just have to use removeChild() to take it away. 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.