Пожалуйста, ознакомьтесь с измененным кодом:
var numOfPlayers = 4;
var ii;
for ( ii = 1 ; ii <= numOfPlayers ; ii++ ) {
var elm = document.getElementById("streamInput"+ii);
elm.index = ii;
elm.addEventListener("keyup", function(event) {
var index = event.target.index;
event.preventDefault();
if (event.keyCode == 13) {
document.getElementById("button"+index).click();
}
});
}
function onClick(e) {
console.log('button clicked:' + e.target.id);
}
<div>
<input type="text" id="streamInput1" /> <input type="button" value="Update" id="button1" onclick=onClick(event) />
</div>
<br/>
<div>
<input type="text" id="streamInput2" /> <input type="button" value="Update" id="button2" onclick=onClick(event) />
</div>
<br/>
<div>
<input type="text" id="streamInput3" /> <input type="button" value="Update" id="button3" onclick=onClick(event) />
</div>
<br/>
<div>
<input type="text" id="streamInput4" /> <input type="button" value="Update" id="button4" onclick=onClick(event) />
</div>