0

I made new project in Visual Studio 2015. It's JavaScript Windows App. I'm trying to make "Hello" application, but when i want compile it i get this error:

0x800a138f - JavaScript runtime error: Unable to set property 'onclick' of undefined or null reference

My code:

document.getElementById("button").onclick = function () {
    var jmeno = document.getElementById("Jmeno").value
    var pop = new Windows.UI.Popups.MessageDialog("<%=Ahoj.Clientid%>" + jmeno);
    pop.showAsync()
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>App1</title>

    <!-- WinJS references -->
    <link href="WinJS/css/ui-dark.css" rel="stylesheet" />
    <script src="WinJS/js/base.js"></script>
    <script src="WinJS/js/ui.js></script>

    <!-- App1 references -->
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/default.js"></script>
    <script src="js/zdravic.js"></script>
</head>
<body class="win-type-body">
    <header>
        <h1>Hello user! :)</h1>
    </header>
    <section>
        <input id='Jmeno' type="text" placeholder="Zadej své jméno"/>
        <button id="button">Klikni na mě!</button>
    </section>
</body>
</html>

And for more, default.css doesn't work for me. Like it wouldn't be there. And yes, i have link it there.

HonzsSedlomn
  • 226
  • 3
  • 12

1 Answers1

3

You are trying to access an element, which has not been loaded yet,

try:

window.onload=function(){
    document.getElementById("button").onclick = function () {
        var jmeno = document.getElementById("Jmeno").value;
        var pop = new Windows.UI.Popups.MessageDialog("<%=Ahoj.Clientid%>" + jmeno);
        pop.showAsync();
    }
}
Szabolcs
  • 1,193
  • 2
  • 10
  • 18
  • `onload` takes way too much time. You only need to wait for the element to parse, not for every single external resource to load. – Sebastian Simon Sep 08 '15 at 22:00