<input type="text">
<input type="text">
<button>1</button>
<button>2</button>
<script>
var a;
var inp = document.querySelectorAll('input');
inp.forEach((el,i)=>el.onfocus = e => {
if(el == e.target) a = i;
});
document.querySelectorAll('button').forEach(el=>el.onclick = e => inp[a].value += el.textContent);
</script>