Click function not working as when called from a function

I had function as below being called when I click on a radio button “foo” and it works as expected when I clicked:

$("#foo").live("click", function () {
    if ($('input:radio[name=foo]:checked').val() == 'foo') {
        $.each(oneArray, function (key, value) {
            $("#foo1").append($("<option></option>")
                         .attr("value", key)
                         .text(value));
        });
        $.each(twoArray, function (key, value) {
            $("#foo2").append($("<option></option>")
                     .attr("value", key)
                     .text(value));
        });
    }
});

But it didn’t worked when I did the following:

checkFoo(){ 
    $("#foo").click();
}

Please correct me if I am doing anything wrong.

Answer

Instead of $("#foo").live("click", function () {... use $("#foo").live("change", function () {..

Hope this help.