IE Treeview 1.1

S

stevobenno

I have spent two days unsuccessfully trying to add cascading checkbox
functionality to the IE Treeview in 1.1.

Has anyone managed to do this.?

I did manage to get some javascript that by all accounts works nicely
in 2.0 but just can't seem to work out how to modify it.

I can get it so that when I call this function from the checkbox click
event EVERY checkbox in the control gets checked and vice versa. Help!


function CascadeCheckmarks(e)
{
// obj gives us the node on which check or uncheck operation has
performed
var element = e.srcElement || e.target;
var parentState = true; //default true;

//checking whether obj consists of checkbox to avoid exception
if (isCheckBox(element))
{
var checkedState = element.checked;

//work our way back to the parent <li> element
while (!isListItem(element))
element = element.parentNode;
recurseThroughChildren(element.firstChild, checkedState); //
set child nodes to checkedState

//from the <li> work our way back to the parent <ul> element
while (!isList(element))
element = element.parentNode;
recurseThroughParents(element, parentState); //set parent
nodes accordingly
}
}

function recurseThroughChildren(element, checkedState)
{
var chkbox;
while(!isNull(element))
{
//mark the child checkbox the same as the parent
chkbox = getCheckBox(element);
if (!isNull(chkbox))
chkbox.checked = checkedState;
//recurse through children of current element
recurseThroughChildren(element.firstChild, checkedState);
element = element.nextSibling;
}
}

function recurseThroughParents(parent, parentState)
{
//if it is an unorderd list, process children
if(isList(parent))
{
//get all child elements that are list items
var item = parent.getElementsByTagName('LI')[0];
var chkbox;

//foreach list item...
while(!isNull(item))
{
//whle the children are not check boxes (only 1 checkbox
per list item)
chkbox = getCheckBox(item.firstChild)
if ((!isNull(chkbox)) && (!chkbox.checked))
parentState = false;
item = item.nextSibling;
}
if (!isDiv(parent.parentNode))
{
var parentCheckBox = getCheckBox(parent.parentNode);
if (!isNull(parentCheckBox))
parentCheckBox.checked = parentState;
}
}
if (!isDiv(parent)) //if it is not a div tag countinue to the next
parent
recurseThroughParents(parent.parentNode, parentState);
}

//return the first checkbox found
function getCheckBox(obj)
{
var ret = null;
while (!isNull(obj))
{
if (isCheckBox(obj))
ret = obj;
else if (obj.childNodes.length > 0)
ret = getCheckBox(obj.firstChild);
if (isCheckBox(ret))
break;
obj = obj.nextSibling;
}
return ret;
}


//helper functions
function isDiv(obj)
{
if (isNull(obj))
return false;
return (obj.tagName == 'DIV');
}

function isCheckBox(obj)
{
if (isNull(obj))
return false;
return (obj.tagName == 'INPUT' && obj.type == 'checkbox');
}

function isList(obj)
{
if (isNull(obj))
return false;
return (obj.tagName == 'UL');
}

function isListItem(obj)
{
if (isNull(obj))
return false;
return (obj.tagName == 'LI');
}

function isNull(obj)
{
return (obj == null);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top