Set style with javascript (textbox) RRS feed

  • Question

  • I'm working on an app, and have one final problem before I'm done. When the VarX = true, should on of the textboxes be hidden, and if the VarX = false, should the textbox style be solid.

    I can change this in the CSS (easy), but I don't really know how to change it, when it's about a variable.

    What I tried, is just to do like this (in the ready function, pagecontrol):

    if (VarX) {
    document.getElementById(height2Input).style.display = none;
    else if (VarX === false) {
    document.getElementById(height2Input).style.display = solid;

    but it's not working. It just returns a error message.
    Friday, March 1, 2013 8:46 PM


  • Hello,

    Try this. Create a simple JavaScript project and add the following contents:

    In your default.html file, add the following body:

        <p>Content goes here</p><br />
        <input type="text" id="txtShowHide" value="Show or Hide this text" /><br />
        <input type="button" id="btnShowHide" value="Hide TextBox" /> 

    In your default.js function, add the following functionality:

        app.onactivated = function (args) {
                args.setPromise(WinJS.UI.processAll().done(function () {
                    document.getElementById("btnShowHide").addEventListener("click", btnShowHideClick, false);

        function btnShowHideClick() {
            if (bShow) {
                document.getElementById("btnShowHide").value = "Show TextBox";
                bShow = false;
                document.getElementById("txtShowHide").style.visibility = "hidden";
            } else {
                document.getElementById("btnShowHide").value = "Hide TextBox";
                bShow = true;
                document.getElementById("txtShowHide").style.visibility = "visible";



    Saturday, March 2, 2013 12:19 AM