Dear Helper,

javascript code:

dhtmlXTreeObject.prototype.getAllChecked=function(){
 return this._getAllChecked("","",1);
}
 
 dhtmlXTreeObject.prototype.getAllCheckedBranches=function(){
 return this._getAllChecked("","",0);
}
 
 
 dhtmlXTreeObject.prototype._getAllChecked=function(htmlNode,list,mode){
 if(!htmlNode)htmlNode=this.htmlNode;
 if(((mode)&&(htmlNode.checkstate==1))||((!mode)&&(htmlNode.checkstate>0))){if(list)list+=","+htmlNode.id;else list=htmlNode.id;}
 var j=htmlNode.childsCount;
 for(var i=0;i<j;i++)
{
 list=this._getAllChecked(htmlNode.childNodes[i],list,mode);
};
 if(list)return list;else return "";
};
<a href="javascript:void(0);" onclick="document.write (tree2.getAllChecked())">Get list of checked</a><br><br>

You may guess, the list is displayed in alert box. but i wanted to save and send them to next page(jsp).......
Plz help me with this.....or else tell me how to recieve the list to an array or arraylist or anyother.

Thanks in advance,
BeanBoy.

Beanboy,

I can't see your code delivering what you want. In particular, this line seems wrong:

list=this._getAllChecked(htmlNode.childNodes[i],list,mode);

It would be much simpler, and stands a chance of working, by building the list in an array rather than a string.

Try this:

dhtmlXTreeObject.prototype.getAllChecked = function(mode) {
	mode = (!mode) ? 0 : mode;
	return this._getAllChecked("", mode);
}
dhtmlXTreeObject.prototype._getAllChecked = function(htmlNode, mode) {
	htmlNode = (!htmlNode) ? this.htmlNode : htmlNode;
	var list = [];
	if( ((mode)&&(htmlNode.checkstate==1)) || ((!mode)&&(htmlNode.checkstate>0)) ) {
		if(htmlNode.id) { list.push(htmlNode.id); }
	}
	for(var i=0; i<htmlNode.childNodes.length; i++) {
		list = list.concat( this._getAllChecked(htmlNode.childNodes[i], mode) );
	}
	return list;
};

Now, to send the list to another page, add this function:

function appendQueryString(link, node){
	if(!link || !link.href) { return false; }
	link.href += (!node) ? '' : ('?' + node.getAllChecked(1).join(','));
	return true;
}

And your html will look like this:

<a href="myPage.jsp" onclick="return appendQueryString(this, tree2);">Get list of checked</a>

I have not been able to test any of this as I don't have the lib that gives dhtmlXTreeObject and I don't know what tree2 comprises.

Airshow

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.