I am having trouble understanding why the function parameter of the event listener isn't accepting just the function. Here's the code:
Variables are declared:
var spanJS = document.getElementById("spanJS")
var txtPlayers = document.getElementById("ContentPlaceHolder1_txtPlayers")
var txtAmount = document.getElementById("ContentPlaceHolder1_txtAmount")
Then associate the event listeners:
txtAmount.addEventListener("keyup", UpdateTotals())
txtPlayers.addEventListener("keyup", UpdateTotals())
Then the function:
function UpdateTotals() {
...
}
This is the whole code. The problem is, when i run it, it executes UpdateTotals() without any keyup event, and the listeners don't work.
If i do the following change, it works like intended:
txtAmount.addEventListener("keyup", function () {
UpdateTotals()
})
txtPlayers.addEventListener("keyup", function () {
UpdateTotals()
})
Can anyone explain me why i can't just put the function's name, i have to "child" it in another function?