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

    Question

  • I am having issues setting the innerHTML of an element on one of my pages. I have three pages total in my app. There is the default page and two others. One of the others works fine and I am able to change the HTML elements from the javascript file. The second page, however, will not allow me to do the same and always returns null. 

    sample HTML:

    <body onload="Test()">
        <div id="Testbody"></div>

    </body>

    sample JS:

    function Test() {
        var mydiv = document.getElementById("Testbody");

        var Change = "<table class='TestTable'></table>";

        mydiv.innerText = Change;

    }

    Friday, February 7, 2014 2:27 AM

All replies

  • Hi JYount,

    So you mean one page works fine and another one got such error message?

    I tried your code and seems works fine, the innerText successfully changed. My question is what's the difference between your first page and another one?

    --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.

    Friday, February 7, 2014 9:27 AM
    Moderator
  • I don't believe there is any difference. Maybe the way I am navigating is incorrect? In the default.html I have two buttons at the top. Each will go to one of the other two pages. in the default.html I have an onclick function attached to the two buttons calling these functions in the default.js file:

    function TestNav() {
        WinJS.Navigation.navigate("/pages/test1/test1.html")
    }
    function Test2Nav() {
        WinJS.Navigation.navigate("/pages/test2/test2.html")
    }

    EDIT:

    I have added a header at the top of each html page to display the page navigation. The two buttons i mentioned in the default.html will navigate between each page fine. It appears though, that when I open the page in Blend, the innerText appears like it should. 

    • Edited by JYount Saturday, February 8, 2014 2:10 AM
    Saturday, February 8, 2014 1:30 AM
  • Hi JYount,

    Sorry for late response.

    I did not see any mistake from the code you provide, but I would like to ask for a reproducible demo for test purpose. You could upload to skydrive and share me the link.

    Thanks.

    --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.

    Wednesday, February 19, 2014 5:39 AM
    Moderator