1 on 1 web hosting - 1316 Part V . Putting JavaScript to Work
Monday, December 31st, 20071316 Part V . Putting JavaScript to Work totals column, so they will call addTotals() function directly rather than this function (the rows don t need recalculation). Number formatting, as explained in Chapter 35, is a detail that scripters must handle themselves (unless you are designing for IE5.5+ and NN6+, which include the number.toFixed() method for number formatting). We can borrow the formatting code from Chapter 35, and use it here as-is: function formatNum(expr,decplaces) { var str = (Math.round(parseFloat(expr) * Math.pow(10,decplaces))).toString() while (str.length <= decplaces) { str = 0 + str } var decpoint = str.length - decplaces return str.substring(0,decpoint) + . + str.substring(decpoint,str.length) } Being able to pick up this function from a different application should reinforce the advantage to writing functions to be as generalizable as possible. Rather than building page-specific references into the formatting function, it accepts parameters that could come from anywhere. Page specifics are left to another function that deals with reading and writing text box values. Cooking up some HTML As we near the end of the scripting part of the document s Head section, we come to two functions that are invoked later to assemble some table-oriented HTML based on the global settings made at the top. One function assembles the row of the table that contains the column headings: function makeTitleRow() { var titleRow =
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.