views:

467

answers:

1

Hi,

I'm using jsTree and I have 2 textboxes:

<input type="text" id="previous_tree_id" value="" /><hr />
<input type="text" id="current_tree_id" value="" />

In the jsTree callback I have:

$("#demo_1").tree({    
    callback : {
        onselect : function (NODE, TREE_OBJ) {
            var selected_tree_id = $(NODE).attr('id');
            $("#current_tree_id").val(selected_tree_id);
        }
    }
});

My problem is

How will I put the ID of the previously selected tree item in the previous_tree_id textbox? My tree id's are just numbers and I have 3 tree items.

Tree ID: 1, 2, 3

So for example if there are 3 tree items and I first select the first tree item then:

Action: - select tree id 1

Output: - textbox previous_tree_id = 1 - textbox current_tree_id = 1

Then after that I will select tree id 2:

Action: - select tree id 2

Output: - textbox previous_tree_id = 1 - textbox current_tree_id = 2

Then after that I will select tree id 3:

Action: - select tree id 3

Output: - textbox previous_tree_id = 2 - textbox current_tree_id = 3

Is it just a javascript logic I have to solve or I'm missing some jsTree function to get the reference/previously selected tree item?

Thanks in advance. - Mark

A: 

Problem Solved with jojo's help.

$("#demo_1").tree({    
    callback : {
        onselect : function (NODE, TREE_OBJ) {
            var selected_tree_id = $(NODE).attr('id');

            // update first the previous_tree_id textbox
            $("#previous_tree_id").val(current);
            // store the new selected tree id in the current_tree_id
            $("#current_tree_id").val(selected_tree_id);
        }
    }
});
marknt15