locked
Exception is about to be caught by JavaScript library code at line 21, column 13 in ms-appx://8e366b75-1f2e-4e96-93a9-cacfb76d2366/js/default.js 0x800a138f - JavaScript runtime error: Unable to get property 'addEventListener' of undefined or null referen

    Question

  • default.html code:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>Ratings</title>
    
        <!-- WinJS references -->
        <link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
        <script src="//Microsoft.WinJS.2.0/js/base.js"></script>
        <script src="//Microsoft.WinJS.2.0/js/ui.js"></script>
    
        <!-- Ratings references -->
        <link href="/css/default.css" rel="stylesheet" />
        <script src="/js/default.js"></script>
    </head>
    <body>
        <h1>Welcome to App World</h1>
       <div>
           <p>Enter UserName</p>
           <input type="text" id="nameInput"/>
           <button id=helloButton"">Start</button>
       </div>
        <div id="greetingOutput"></div>
    </body>
    </html>
    

    default.js code:

    (function () {
        "use strict";
    
        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());
                //Retrieve the Button and register button handler
                var helloButton = document.getElementById("helloButton");
                helloButton.addEventListener("click", buttonClickHandler, false);
            }
        };
    
        app.oncheckpoint = function (args) {
            // TODO: This application is about to be suspended. Save any state
            // that needs to persist across suspensions here. You might use the
            // WinJS.Application.sessionState object, which is automatically
            // saved and restored across suspension. If you need to complete an
            // asynchronous operation before your application is suspended, call
            // args.setPromise().
        };
    
        function buttonClickHandler(eventInfo) {
            var userName = document.getElementById("nameInput").value;
            var greetingString = "Hello" + userName + "Welcome";
            document.getElementById("greetingOutput").innerText = greetingString;
             
        }
    
    
        app.start();
    })();
    

    Please Tell me What was the problem and Solution for this..

    Sunday, July 27, 2014 6:03 AM

Answers

  • Hi Prabhakar,

    Really Easy to fix, in your HTML:

    <button id=helloButton"">Start</button>
    
    change to 
    
    <button id="helloButton">Start</button>

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Monday, July 28, 2014 7:13 AM
    Moderator