Hey Jen:
Before solving your problem, there are two optimization suggestions on your code.
1. You don't need to add this line in your UPDATE code:
$(document).on('blur change', '.lookupCondition2 input', autofill);
Instead, you can just change this code line:
$('.lookupCondition2').change(autofill);
into:
$('.lookupCondition2 input').change(autofill);
or:
$('.lookupCondition2 input').on('change blur', autofill);
2. It would be better to trigger the 'change' event not only for 'condition2', but also for 'condition1'. With this code, If you want to make any change in 'condition1' after inputting value into 'condition2', you can still run the autofill function.
$('.lookupCondition1 input, .lookupCondition2 input').change(autofill);
For your question, here is the possible solution:
In jQuery, the event 'blur', 'focus' or 'change' are active when you focus on or tab out certain field. Since the event you use to trigger the autofill function is 'blur' or 'change', this function won't be called unless the browser detect focus behavior in the 'lookupCondition2 input' field.
I am not sure how you copy the 'condition2' field value from another field. If you also implement it with jQuery, then things will be easier.
Suppose the class name of the field where 'condition2' copy value from is: 'copyfrom'.
One possible solution is to attach the 'change' event on the 'copyfrom' field instead of the 'condition2'. Then we can trigger autofill function without focusing on the 'condition2' field.
Here is the suggested code, you can change it according to your use case.
$(document).ready(function () {
function autofill() {
$('.autofill').trigger('click');
}
$('.lookupCondition1 input, .lookupCondition2 input').change(autofill);
$('.copyfrom input').on('change', function(){
//get copy value from the 'copyfrom' field
var copyValue = $(this).val();
//set the value of 'condition2' with copy value, and trigger the change event
$('.lookupCondition2 input').val(copyValue).change();
})
});
Hope the above code can solve your problem. Let me know if you have any questions :)