Hey Guys.
I use the JavaScript/HTML blank app template. I have this button and want it to call a function called btnClick(). I don't really think that anything is wrong with my HTML but here it is:
EDIT: The problem is that I get an error message - "'btnClick is not definated"
default.html :
<body>
<h1 id="whatText">Some kind of secret text here...</h1>
<div id="bodyPic"><button onclick="javascript:btnClick();" style="width: 300px; height: 300px;">Find out!</button></div>
<div id="aswTxt"></div>
</body>
default.js :
(function () {
"use strict";
WinJS.Binding.optimizeBindingReferences = true;
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application has been reactivated from suspension.
// Restore application state here.
}
args.setPromise(WinJS.UI.processAll());
}
};
app.oncheckpoint = function (args) {
};
function btnClick () {
var rand = Math.round(Math.random());
var asw;
if (rand === 1) {
asw = "David says yes!";
}
else {
asw = "David says no!";
}
document.getElementById("aswTxt") = asw;
}
app.start();
})();
I don't know if I wrote the function the wrong place or what? I didn't really know where to write it and that could be the problem. Also I tried to write onclick:"javascript:btnClick();" and without the JavaScript (in the HTML).