global/local var in a function


I have a little problem with a function. It calls him self and the var i is lost! after the call!

can anybody help me?

function change_check_all(tree_item) {
a = document.all[tree_item + "_check"];
b = document.all[tree_item + "_count"];
for(i=0;i<b.value;i++) {
if (a.value=="off") {
change_check_to(tree_item + "_" + i, 0);
} else {
change_check_to(tree_item + "_" + i, 1);
change_check_all(tree_item + "_" + i, i);


  • Well I can help you but I'd like to give you a general tipp when writing functions:
    It is very hard to understand your source code because when you look at it the first time you can't see which subfunction is where or where it start or ends.
    do that and that

    Also when posting a code like this some comments would help in understanding it!


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion