1 Reply Latest reply on Oct 29, 2013 1:31 PM by elainecc

    Inserting dynamic calculation in javascript to the stage


      I'm working with a partner on calculating the area of a rectangle, as a user changes its size. We're using javascript and so far have:


      function calculateArea() {

      var width = +document.getElementById("width").value;

      var height =+document.getElementById("height").value;

      var area = width * height;

      document.getElementById("area").value = area;




      Width <input type="Text" name="width" id="width" size="4"> 

      Height <input type="Text" id="height" name="height" size="4" onkeyup=""> <br><br>

      Area <input type="Text" name="area" id="area" size="4"> <br><br>

      <input type="button" name="calculate" id="area" size="4" onclick="calculateArea()" value="calculate">


      The main problem is that we're having difficulty getting the result of the calculation to show up in a textbox on the stage. 


      The subproblem is that because we can't see the result, we don't know whether the code is calculating correctly!


      Any help would be appreciated!

        • 1. Re: Inserting dynamic calculation in javascript to the stage
          elainecc Adobe Employee

          You can use the command console.log() to post the info to the console, and see that in your browser's console.  If you want to have it show up in your textbox, you can refer to it like this:


          Assuming the name of the element is "myTextBox":

          sym.$("myTextBox").html(area.toString()); // use toString() because area is a numeric value


          Hope that helps!



          1 person found this helpful