<input name="1" type="text" id="1" value="">
<input name="2" type="text" id="2" value="">
<input name="3" type="text" id="3" value="">
<input name="4" type="text" id="4" value="">
function collectValues(target, ...sources) {
const onInput = () => target.value = sources.map(n => n.value).join(', ');
sources.forEach(n => n.addEventListener('input', onInput));
return () => sources.forEach(n => n.removeEventListener('input', onInput));
}
collectValues(...document.querySelectorAll('input'));