Hello I've been trying to create a function that creates objects and another function that can delete them when triggered the objects code is generated server side and triggers the function passing the object data.
The object data sort of looks like this

<OBJECT id="RandomNumbers" width="0" height="0"
		style="position:absolute; left:0;top:0;"
		CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
		type="application/x-oleobject">

		<PARAM NAME="URL" VALUE="BlahBlah.mp3">
		<PARAM NAME="SendPlayStateChangeEvents" VALUE="True">
		<PARAM NAME="AutoStart" VALUE="True">
		<PARAM name="uiMode" value="none">
		<PARAM name="PlayCount" value="9999">
		<PARAM name="volume" value="50">
	</OBJECT>

I need them to have two functions one that adds the object code into the html

function addObject(objectdata)

and one that destroys it by id the

function deleteObject(id)

I've tried a few methods I looked up but whenever I try to get them to work the way I need them they throw errors...
It would be very cool if you could also get it under a div tag.

If you can post a link to what I need or better yet the code to do it I would appreciate it.

Recommended Answers

All 5 Replies

function deleteObject(id)

continue that line with this:

{
id.parentNode.removeChild(id);
}

and you're done. (assuming you've already stored the targeted element in your "id" var globally),
otherwise you should invoke your function this way: deleteObject(document.getElementById("elementId"))

<script type="text/javascript">
        function deleteObject(id) {
          var/obj = document.getElementById(id);
          obj.parentNode.removeChild(obj);
          }
        </script>

This is throwing errors before its even called?
Am I missing something simple?

<script type="text/javascript">
function deleteObject(id) {
var/obj = document.getElementById(id);
obj.parentNode.removeChild(obj);
}
</script>

This is throwing errors before its even called?
Am I missing something simple?

"errors"? :')
yeah, of course it is throwing errors... - What's the thing in red doing up there?!!

I'm sure I instructed you to:

continue that line with...:

function deleteObject(id){
      id.parentNode.removeChild(id);
}

and you're done.

and that in case you haven't done something like: var id = document.getElementById("elementId") to be able to call the function in short: deleteObject(Id) earlier in your script; you can invoke this same function with the following syntax: deleteObject(document.getElementById("elementId")) wrapping it on clean now:

<script type="text/javascript">
	function deleteObject(id) {
		id.parentNode.removeChild(id);
	}

		var marked4Deletion = 
		document.getElementById( "RandomNumbers" );

	deleteObject( marked4Deletion );
</script>

I've presumed that you are targeting the object with id = "RandomNumbers" for deletion.

---
If you have further questions, please don't hesitate to ask.

Great the delete works. Now how do I add the objects code into the html page?
I've tried innerHtml but it causes the object to stutter...
newElement seems to do what I need because I can get it to add text without stuttering but I'm having trouble getting it to add objects

to my point of view. There is absolutely no need or logic in creating and destroying multi-purpose structural objects of the document body just so you can play another content.

Do you buy yourself an new player for each disk you want to play or you simply change the disk?
Than you can simply change the source on the current object.

var player = document.getElementById("RandomNumbers")
player.URL = "new BlahBlah.mp3"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.