locked
Unable to add dynamic content... but only using innerText

    Question

  • Hi all,

    I am getting dynamic content errors when using innerText. I tried using toStaticHTML as well, but it still throws errors. Any clues? My code is as follows:

    // For an introduction to the Blank template, see the following documentation:
    // http://go.microsoft.com/fwlink/?LinkId=232509
    (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());
                
                // Calculate budget
                // Retrieve the button and register our event handler. 
                var budgetButton = document.getElementById("calculate");
                budgetButton.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(calculate) {
            var income = document.getElementById("income").value;
            var expense = document.getElementById("expense").value;
            var remaining = income - expense;
            var outputmessage = "Income:" + income + "Expense:" + expense + "Remaining:" + remaining
            document.getElementById("result").innerText = outputmessage;
        }
    
        app.start();
    })();
    


    Personal Blog: http://thebitsthatbyte.com

    Friday, February 14, 2014 5:12 AM

Answers

All replies

  • what error are you getting, as it works fine for me, with the following HTML:

    <input id="income" />
    <input id="expense" />
    <div id="result"></div>
    <button id="calculate">Calc</button>

    Friday, February 14, 2014 8:09 AM
  • Hi Andy,

    Here is the body of my HTML:

    <body>
        <p>Budget Calculation</p>
                Income: <input id="income" type="number" name="income">
                Expense: <input id="expense" type="number" name="expense">
                <button id="calculate">Calculate</button>
        <div id="result"></div>
    </body>

    And here is my JavaScript:

    // For an introduction to the Blank template, see the following documentation:
    // http://go.microsoft.com/fwlink/?LinkId=232509
    (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());
                
                // Calculate budget
                // Retrieve the button and register our event handler. 
                var budgetButton = document.getElementById("calculate");
                budgetButton.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(calculate) {
            var income = document.getElementById("income").value;
            var expense = document.getElementById("expense").value;
            var remaining = income - expense;
            var outputmessage = "Income:" + income + "Expense:" + expense + "Remaining:" + remaining
            document.getElementById("result").innerText = outputmessage;
        }
    
        app.start();
    })();
    

    Any clues?

    Thanks for your help,

    Kelly


    Personal Blog: http://thebitsthatbyte.com

    Saturday, February 15, 2014 1:34 AM
  • Here are the errors:

    HTML1701: Unable to add dynamic content '<select t=''><option selected=''></option></select>'. A script attempted to inject dynamic content, or elements previously modified dynamically, that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content, or explicitly create elements and attributes with a method such as createElement.  For more information, see http://go.microsoft.com/fwlink/?LinkID=247104.

    HTML1701: Unable to add dynamic content '<input type='radio' checked='checked' name='t'/>'. A script attempted to inject dynamic content, or elements previously modified dynamically, that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content, or explicitly create elements and attributes with a method such as createElement.  For more information, see http://go.microsoft.com/fwlink/?LinkID=247104.
    File: about:blank

    The weird part is that I don't have any Select or Radio Inputs in my code...


    Personal Blog: http://thebitsthatbyte.com

    Saturday, February 15, 2014 6:59 PM
  • Update, if I remove the jquery script link, the error went away... but I want to use jQuery. Very odd. I am using jQuery-2.1.0.min.js

    Personal Blog: http://thebitsthatbyte.com

    Sunday, February 16, 2014 12:09 AM
  • OKAY!!! If I switch from 2.1.0 to 2.0.2 I don't get the errors.

    Please pass the word along that version 2.1.0 produces the HTML1701 errors.


    Personal Blog: http://thebitsthatbyte.com

    Sunday, February 16, 2014 12:14 AM
  • I can confirm this problem. Funny how every time MS attempts at JS, they destroy it (IE, MS AJAX, WinJS).
    Tuesday, March 25, 2014 10:52 AM