I have the following code in home.js of the default NavigationApp:
(function () {
"use strict";
WinJS.UI.Pages.define("/pages/home/home.html", {
// This function is called whenever a user navigates to this page. It
// populates the page elements with the app's data.
ready: function (element, options) {
var submit = document.getElementById("submitBtn");
submit.addEventListener("click", myFunc());
}
});
function myFunc() {
// Do some stuff here
}
})();
The problem I have is that the function myFunc() executes immidiately the app starts, and not on the pressing of the submit button as I expected; why is this?
You are adding the result of
myFunc()to your listener, you want to be doingsubmit.addEventListener("click", myFunc)to add the function as the callback instead of the result of the function.