views:

24

answers:

1

Hi

Step 1

I've two screens one is parent and the other one is child. On click of a button in the parent window the child popup will open.

Step 2

On click of a button in child i'm displaying the html(viewsource) of parent window in a textbox(.net) and holding in a hidden variable hdnSource too.

Step 3

I've 4 checkboxes in the child window.

If the checkbox is not checked, then that part of html should be removed.

eg: cbxPersonal, cbxProfessional

if cbxProfessional is unchecked I should remove divProfessional from html which is in hdnSource and display in the textbox

Can anyone help me to do the 3rd part of coding.

Since the html is in the variable, I'm not able to find the div with document.getElementById

A: 

Trying to futz about hacking bits out of HTML strings is going to be annoying and buggy. Instead, do the removal on the DOM Nodes, before you've turned them into an HTML string.

To avoid actually removing the real divs from the parent page's visible DOM, clone the nodes before operating on them. eg.

var copy= opener.document.body.cloneNode(true);

if (!document.getElementById('cbxPersonal').checked) {
    var div= copy.getElementById('divPersonal');
    div.parentNode.removeChild(div);
}

var html= copy.innerHTML;
bobince
'divPersonal' is in the parent. and I should remove it from the opener html if 'cbxPersonal' in the child window is not checked
spj
ah ok - updated code to use `document` instead of the opener document to read the checkbox.
bobince