Jump to content

[SOLVED] Need the line of code to delete an object


cleary1981

Recommended Posts

Hi,

 

I have a function that creates an object and now im working on the function to delete objects. I have most of the code written but cant figure out how to actually delete the object. Should I use removechild or what. Take a look at my code. I have included the create object function as it might be some help.

 

function createObject() {
var g_model = document.getElementById("model").value;
g_objName = document.getElementById("objName").value;
g_projID = document.getElementById("projID").value;
var url = "create_object.php?g_model=" + escape(g_model) + "&g_objName=" + escape(g_objName) + "&g_projID=" + escape(g_projID);
request.open("GET", url, true);
request.onreadystatechange = showObject;
request.send(null);
}
function showObject (){
document.getElementById('objName').value = "";
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");
var 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);
}
}

 

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);
var arr = new Array(); arr = document.getElementsByTagName("div");  //make array of all divs with id = newObject
// alert("Total Number of HTML Elements Found: " + document.documentElement.getElementsByTagName("div").length); 
for(var i=0; i < arr.length; i++) 
	{
		//check innerHTML against obj_name
		result = document.documentElement.getElementsByTagName("div").item(i).innerHTML;
		if (result == obj_name)
		{
			//delete current object
		}
	}
}

Link to comment
Share on other sites

Javascript

 

delete

 

The delete operator is used to delete an object, an object's property or a specified element in an array, returning true if the operation is possible, and false if not. With the defined object 'fruit' below, the following delete operations are possible:

 

Code:

fruit = new Object;

fruit.name = 'apple';

fruit.color = 'green';

fruit.size = 'large';

 

delete fruit.size;

 

with(fruit)

  delete color;

 

delete fruit;

 

NOTE:

 

To delete an object's property, you must precede that property's name with the name of the object, unless it's used in a with statement.

 

The delete operator can also be used to delete an element of an array. This does not affect the length of the array or any of the other elements but changes the deleted element to undefined. The following example creates an array called 'fruit' and then deletes element #2 (orange):

 

Code:

fruit = new Array ("apple", "pear", "orange", "cherry", "grape");

delete fruit[2];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.