/    Sign up×
Community /Pin to ProfileBookmark

Problem with removeChild();

Hi all, my problem is that, I have two function on javascript:
Function1 for create control on the page and Function2 for remove that control.

Function1 is work fine, it can create control on page. Function2 also work fine it can remove that control from the page.

But when i use function1 to create control again it got an error it say “The control with that ID already exist on the page”. It seem to be the control is not remove from the page, it just hide. It’s maybe wrong with my function2.

===Here my function1 to create control on the page===

[code]
function createDraggableDiv()
{
//get the cameraID from uxCameraName…
try
{
var IndexValue = $get(‘<%=uxCameraName.ClientID %>’).selectedIndex;
var SelectedVal = $get(‘<%=uxCameraName.ClientID %>’).options[IndexValue].value;
}
catch(err)
{
alert(‘No camera has been selected!’);
return;
}

var panel= document.createElement(“div”);
panel.className = “PanelCamera”;
panel.setAttribute(“id”,”uxPanelDrag”+SelectedVal);

var panelHandle = document.createElement(“div”);
panelHandle.style.height=”21px”;
panelHandle.style.width=”auto”;
panelHandle.className=”sci-picker-header-camera”;
panel.appendChild(panelHandle);

var btnquit = document.createElement(“input”);
btnquit.type=”image”;
btnquit.style.height=”17px”;
btnquit.style.width=”16px”;
btnquit.title = “Close/Remove camera”;
btnquit.src=”/AjaxDragDrop/image/close.png”;
panelHandle.appendChild(btnquit);
btnquit.onclick = function(){removeDraggableDive(SelectedVal); return false;};

var btnpin = document.createElement(“input”);
btnpin.type=”image”;
btnpin.className=”ImagePin”;
btnpin.title = “Locking/Release camera”;
btnpin.src=”/AjaxDragDrop/image/pin_out.png”;
panelHandle.appendChild(btnpin);
btnpin.onclick = function(){PinINPinOUT(this); return false;};

var image= document.createElement(“img”);
image.src=”/AjaxDragDrop/image/camera_enabled_65.png”;
image.className = “ImageCamera”;
panel.appendChild(image);

try
{
var target = $get(‘containerDiv’).appendChild(panel);
addFloatingBehavior(panel, panelHandle);
}
catch(err)
{
panel.parentNode.removeChild(panel);
//alert(‘This camera already exist on site map!’);
alert(err.description);
return;
}
}

function addFloatingBehavior(ctrl, ctrlHandle)
{
var obj = $create(Custom.UI.FloatingBehavior, {‘handle’: ctrlHandle}, null, null, ctrl);
}
[/code]

===Here my function2 to remove control from the page===

[code]
function removeDraggableDive(ItemID)
{
try
{
if (document.getElementById(“uxPanelDrag”+ItemID))
{
var ctlParent = document.getElementById(“uxPanelDrag”+ItemID);
ctlParent.parentNode.removeChild(ctlParent);
}
}
catch(err)
{
alert(err.description);
}
}
[/code]

any idea?, please help.
thank

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @seang_sophorn spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...