const buttonOne = document.getElementById("btn1");
const inputfieldOne = document.getElementById("username1");
inputfieldOne.addEventListener("keyup", function(e) {
const valueOne = e.target.value;
if (valueOne === "") {
buttonOne.disabled = true;
buttonOne.style.backgroundColor = "grey";
} else {
buttonOne.disabled = false;
buttonOne.style.backgroundColor = "orange";
}
})
<div class="container">
<input id="username1" placeholder="Username" class="input" />
<button disabled id="btn1" type="button" class="button">Submit</button>
</div>
Currently, this code only works for one specific input and button pair. How can I modify the JavaScript to apply to multiple pairs of input fields and buttons?
I would appreciate any assistance in solving this issue. Thank you.
If you have a complete jQuery solution, that is also welcome.