Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recursive programming problem using checkboxes

Status
Not open for further replies.

CaptainSensible

Programmer
Jun 27, 2002
7
CH
Hello,
I'm having trouble with a function using recursive programming to uncheck checkboxes, organized as a tree, with parents, child...

As an example:

<LI class=&quot;Collection-LI-first&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;common&quot; value=&quot;common&quot; tabindex=&quot;debut+3&quot; id=&quot;3&quot; parentid=&quot;0&quot; onclick=&quot;doOnClick(this)&quot;>common</INPUT>
<BR></BR>
</LI>
<UL>
<LI class=&quot;Collection-LI-first&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;classes&quot; value=&quot;classes&quot; tabindex=&quot;debut+4&quot; id=&quot;4&quot; parentid=&quot;3&quot; onclick=&quot;doOnClick(this)&quot;>classes</INPUT>
<BR></BR>
</LI>
<UL></UL>
<LI class=&quot;Collection-LI-first&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;lib&quot; value=&quot;lib&quot; tabindex=&quot;debut+5&quot; id=&quot;5&quot; parentid=&quot;3&quot; onclick=&quot;doOnClick(this)&quot;>lib</INPUT>
<BR></BR>
</LI>
<UL></UL>
</UL>

So I use this function to uncheck all the childs, and childs of the childs... but somewhere there is a problem with the pointers and it leads to unexepected behavior.

function ClearChildren(checkboxId) {
for (i=eval(debut); i<collection.elements.length; i++){
var temp=collection.elements;
if (eval(temp.parentid) == eval(checkboxId)){ temp.checked=false;
if (hasChildren(temp)) ClearChildren(temp.id);}
}
}

Could anyone help me out? Thanks in advance.
 
whats debut?

whats parentid, is this actually a tag attribute?

wheres the haschildren and clearchildren functions?

whats the error message and what line is it pointing to?
 
Sorry,
debut is just an integer value (=0); yes, id and parentid, are tag attributes, wich I use to make the tree structure.
hasChildren is just a small simple function wich looks if there are other checkboxes with a parentid==id, (no problem with it)
clearChildren is the recursive call;
In fact there are no error messages, but the
For example, with this html code:

<LI class=&quot;Collection-LI-first&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;webapps&quot; value=&quot;webapps&quot; tabindex=&quot;debut+12&quot; id=&quot;12&quot; parentid=&quot;0&quot; onclick=&quot;doOnClick(this)&quot;>webapps</INPUT>
<BR></BR>
</LI>
<UL>
<LI class=&quot;Collection-LI-first&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;examples&quot; value=&quot;examples&quot; tabindex=&quot;debut+13&quot; id=&quot;13&quot; parentid=&quot;12&quot; onclick=&quot;doOnClick(this)&quot;>examples</INPUT>
<BR></BR>
</LI>
<UL>
<LI class=&quot;Collection-LI-first&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;images&quot; value=&quot;images&quot; tabindex=&quot;debut+14&quot; id=&quot;14&quot; parentid=&quot;13&quot; onclick=&quot;doOnClick(this)&quot;>images</INPUT>
<BR></BR>
</LI>
<UL></UL>
<LI class=&quot;Collection-LI-first&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;jsp&quot; value=&quot;jsp&quot; tabindex=&quot;debut+15&quot; id=&quot;15&quot; parentid=&quot;13&quot; onclick=&quot;doOnClick(this)&quot;>jsp</INPUT>
<BR></BR>
</LI>
<UL>

If &quot;images&quot; and &quot;jsp&quot; are checked, a click on the ancestor webapps would clear all the children checlboxes. In fact, only &quot;images&quot; is cleared. So it seems, the context is lost because after the return from the recursive call, the rest of the &quot;for&quot; loop is not executed. If I don't do the recursive call, the for loop is correctly executed and all the children on the same level are unchecked. I hope my english is understandable! If not, I'll try to explain more.
Thank you.
 
Ok, sorry, it was just a minor problem:

for (i=eval(debut); i<collection.elements.length; i++){
...

I forgot to write &quot;var&quot;!!

for (VAR i=eval(debut); i<collection.elements.length; i++){
...

I didn't know I had to do this.
Ok, thanks for the interest. Good day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top