Q:

How to enable a button when two fields are changed.

I am trying to enable a button if two of my fields have keydown event. Below is the code which I tried but would not work. Any ideas ? 
var dateField = 0;
var termOfPaymentField = 0;
$(jq('overlay.givendate'))
    .on('change keydown', function () { 
    dateField = 1;
    });
$(jq('overlay.fielddata'))
    .on('change keydown', function () {
    termOfPaymentField = 1;
    });
if (dateField === 1 && termOfPaymentField === 1) {
    $('.ui-dialog-buttonpane button').button({ disabled: false });
    dateField = 0
    termOfPaymentField = 0;
}

A:

As well as setting the flags, you actually need to run the if condition. Try this:
var dateFieldChanged = false;
var termOfPaymentFieldChanged = false;

$(jq('overlay.givendate')).on('change keydown', function () { 
    dateFieldChanged = true;
    checkFields();
});
$(jq('overlay.fielddata')).on('change keydown', function () {
    termOfPaymentFieldChanged = true;
    checkFields();
});

function checkFields() {
    if (dateFieldChanged && termOfPaymentFieldChanged) {
        $('.ui-dialog-buttonpane button').button({ disabled: false });
        dateFieldChanged = false;
        termOfPaymentFieldChanged = false;    
    }
}

Note I also changed the flags to boolean values.

