I'm having an issue with some of my code executing in an unexpected order. I have two buttons each with a function bound to the click event. One button is 'cancel' and it makes some display changes. The second button is 'done' which saves changes by writing them to a hidden input field and then triggers the event handler on 'cancel'. This is what my code looks like.
/*done link*/
$("#donelink").bind('click', function() {
var idvalues = $.map($(".ledgerline input:checkbox:checked"), function(el, i) {
return $(el).val().toString();
}).join(',');
$("#my_input").val(idvalues);
$("#cancellink").triggerHandler('click');
});
/*cancel link*/
$("#cancellink").bind('click', function() {
/*some basic css and other property changes*/
$(".ledgerline input:checkbox:checked").parent().parent().trigger('click');
});
/* The function bound to this event:
$(".ledgerline input:checkbox:checked").parent().parent().trigger('click');
*/
function {
/* other stuff */
$(this).find("input:checkbox").remove();
}
What I expect to happen is that when I click on the 'done' link it will find values from all the checkboxes and write them to #my_input. And then it will hit the cancel link, removing all the checkboxes. What instead happens is that all the checkboxes are first removed, and then an empty string is written in as the value.
Any help? I don't understand why this is happening.