Tech Off Post

Single Post Permalink

View Thread: More ECMAScript fun!
  • User profile image
    Maurits

    Here's a fixed version.

    Case sensitivity is important to Firefox.

    There's no such attribute as "type" on a <button>, which broke IE.


    <h3>Content</h3>
    <div id="divTxaTools">&nbsp;</div>
    <textarea cols="60" rows="20" id="txaContent"></textarea>

    <script>
    var txaTools;
    var txaContent;

    var btnHeightInc, btnHeightDec, btnWidthInc, btnWidthDec;

    window.onload = function() {

        txaTools = document.getElementById("divTxaTools");
        txaContent = document.getElementById("txaContent");
       
        btnHeightInc = document.createElement("button");
        btnHeightDec = document.createElement("button");
        btnWidthInc  = document.createElement("button");
        btnWidthDec  = document.createElement("button");
       
        btnHeightInc.innerHTML = "Increase Height";
        btnHeightDec.innerHTML = "Decrease Height";
        btnWidthInc.innerHTML  = "Increase Width";
        btnWidthDec.innerHTML  = "Decrease Width";
       
    //    btnHeightInc.type = "button";
    //    btnHeightDec.type = "button";
    //    btnWidthInc.type  = "button";
    //    btnWidthDec.type  = "button";
       
        btnHeightInc.onclick = HeightIncrease;
        btnHeightDec.onclick = HeightDescrease;
        btnWidthInc.onclick  = WidthIncrease;
        btnWidthDec.onclick  = WidthDecrease;
       
        txaTools.appendChild(btnHeightInc);
        txaTools.appendChild(btnHeightDec);
        txaTools.appendChild(btnWidthInc);
        txaTools.appendChild(btnWidthDec);
       
    }

    function HeightIncrease() {
        txaContent.rows = txaContent.rows + 1;
    }
    function HeightDescrease() {
        txaContent.rows = txaContent.rows - 1;
    }
    function WidthIncrease() {
        txaContent.cols = txaContent.cols + 1;
    }
    function WidthDecrease() {
        txaContent.cols = txaContent.cols - 1;
    }
    </script>