I'm trying to dynamically insert commas into each text input as you type numbers. However, it's only working for the first input and I can't figure out why.
Here's my code:
HTML
<input type="text" class="number" id="annual-income" name="annual_income">
<input type="text" class="number" id="commission" name="commission">
<input type="text" class="number" id="bonus" name="bonus">
<input id="income-button" type="button" value="Next">
Javascript
var el = document.querySelector('input.number');
el.addEventListener('keyup', function (event) {
if (event.which >= 37 && event.which <= 40) return;
this.value = this.value.replace(/\D/g, '')
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
});