I have the following HTML code and I am looking to trigger a function based on the input in any of the input fields, regardless of the field number.
<input type="text" pattern="[0-9]*" name="code" maxlength="1" autofocus="autofocus" id="input1" class="input1"/>
<input type="text" pattern="[0-9]*" name="code" maxlength="1" id="input2" class="input2"/>
<input type="text" pattern="[0-9]*" name="code" maxlength="1" id="input3" class="input3"/>
<input type="text" pattern="[0-9]*" name="code" maxlength="1" id="input4" class="input4"/>
I want to simplify this by calling a single function for all input fields.
$("#input1").on('input', function () {
console.log("this is input1");
});
$("#input2").on('input', function () {
console.log("this is input2");
});
$("#input3").on('input', function () {
console.log("this is input3");
});
$("#input4").on('input', function () {
console.log("this is input4");
});