SavaryNicolas
SavaryNicolas

Reputation: 33

Dynamically click with Jquery after onload

first i explain the context then the problem. I am using jstree to transform a list into a treeview, son onPostBack i get a HTML list that the jsTree jQuery code transform into a treeview. I choose to use checkboxes.

Now when i have a post back, i lost all my checked boxes (that is normal) but i want to rechecked them with the same value than the previous one. I save them into session, and i don't really know how to recheck; i search on Google and found a lot of solution but using Json data binding, i use Html data. So i think that maybe i could just dynamically click on each boxes needed to be checked just after the onload.

I know it's probably not the proper way of doing that, but i really want to do it for understand a little more Jquery so i could figure after that of a better way.

So i wrote a function that callback the session, and dynamically click on each checked boxe with the correct id. When i put it into a button click, it worked, but i assume it's because the click is done after the onload. What i want is to use that function, at the onload but after the jstree Jquery have finish to transform the list into a treeview.

I try some method found here without sucess (probably because i'm too newbie on Jquery and allergic to javascript :] .

Upvotes: 0

Views: 805

Answers (1)

Thomas Clayson
Thomas Clayson

Reputation: 29925

You should use trigger.

$('input[type=checkbox]').trigger('click');

You can do this on jstree's loaded event like so:

$('element').bind("loaded.jstree", function (event, data) {
    $('input[type=checkbox]').trigger('click');
}).jstree(...);

Upvotes: 2

Related Questions