Frequently Asked Questions?

Frequently Asked Questions?


You've mentioned the Document Object Model a couple of times. What's that? And what does it have to do with Katie's web report?


The Document Object Model, called the DOM for short, is how web browsers store and represent HTML pages. By working with the DOM, you can dynamically update a web page, like you're doing with Katie's report. We'll look at the DOM in detail in Chapter 4, but for now, you can just use the text-utils.js utility file, and not worry too much about the details of the DOM.

Just Do It Solutions

You're ready to finish up the updatePage() function on your own. Below is the code for updatePage(), but there are plenty of blanks left to be filled in. Try and figure out the code that belongs in each blank, and write in your answers.

    function updatePage() {
      var newTotal = request.responseText;
      var boardsSoldEl = document.getElementById("boards-sold");
      var cashEl = document.getElementById("cash");
      replaceText(boardsSoldEl, newTotal);

      /* Figure out how much cash Katie has made */
      var priceEl = document.getElementById("__Price__");
      var price = getText(__PriceEI__);
      var __CostEI__ = document._getElementByld_("cost");
      var cost = getText(costEl);getText() is from text-utils.js. It will take any
element, and return the text within that element.
      var cashPerBoard = __Price__ - __Cost__;
      var cash = _cashPerBoard_ * __newTotal__;

      /* Update the cash for the slopes on the form */
      cash = Math.round(cash * 100) / 100;This little trick makes sure that the cash
total has only two decimal places, like a normal dollar value.
      replaceText(cashEl, ___cash____);

 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows