I got a problem when trying to make onchange listener for input in JavaScript:
var apple = document.getElementById("apple");
apple.addEventListener("change", validate("apple"));
function validate(fruitName){
var qty = parseInt(document.getElementById(fruitName).value);
console.log(qty);
}
I am trying to check everytime when the user input something for 'apple' input, I will print the quantity at console. But by doing this, It only ran the first time when I refreshed the browser by printing out a NaN and does not work even when I changed the input for 'apple'.
Any ideas?
Thanks in advance.