1426 Part V . Putting JavaScript to Work (Web host server)

1426 Part V . Putting JavaScript to Work function sortDBByTotalQuota(a, b) { if (document.getElementById( orderChooser ).value == inc ) { return (a.totalQuotaPct - b.totalQuotaPct) } else { return (b.totalQuotaPct - a.totalQuotaPct) } } For this application, all sorting functions branch in their execution based on the choice made in the Ordered SELECT element on the page. The relative position of the two array elements under test in these simple subtraction comparison statements reverses when the sort order is from low to high (increasing) and when it is from high to low (decreasing). This kind of array sorting is extremely powerful in JavaScript and probably escapes the attention of most scripters. Constructing the table As recommended back in Chapter 27 s discussion of TABLE and related elements, it is best to manipulate the structure of a TABLE element by way of the specialized methods for tables, rather than mess with nodes and elements. The drawTextTable() function is devoted to employing those methods to create the rendered contents of the table below the headers (which are hard-wired in the document s HTML). Composing an eleven-column table requires a bit of code, and the drawTextTable() s length attests to that fact. You can tell by just glancing at the code, however, that for big chunks of it, there is a comfortable regularity that is aided by the JavaScript object that holds the data. Additional calculations take place while the table s elements are being added to the TABLE element. Column totals are accumulated during the table assembly (row totals are calculated as the object is generated and preserved as properties of the object). A large for loop cycles through each (sorted) row of the dbarray; each row of the db array corresponds to a row of the table. Class names are assigned to various rows or cells so that they will pick up the style sheet rules defined earlier in the document. Another subtlety of this version is that the region property of a sales rep is assigned to the titleproperty of a row. If the user pauses the mouse pointer anywhere in that row, the name of the region pops up briefly. function drawTextTable() { var newRow var accumQ1F = 0, accumQ1A = 0, accumQ2F = 0, accumQ2A = 0 var accumQ3F = 0, accumQ3A = 0, accumQ4F = 0, accumQ4A = 0 deleteRows(document.getElementById( mainTableBody )) for (var i = 0; i < db.length; i++) { newRow = document.getElementById( mainTableBody ).insertRow(i) newRow.className = db[i].region newRow.title = db[i].region + Region appendCell(newRow, rep , db[i].firstName + + db[i].lastName) appendCell(newRow, Q1 , db[i].sales.Q1_2000.forecast +
+ db[i].sales.Q1_2000.actual) appendCell(newRow, Q1 , db[i].sales.Q1_2000.quotaPct + % ) appendCell(newRow, Q2 , db[i].sales.Q2_2000.forecast +
+ db[i].sales.Q2_2000.actual)
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

Leave a Reply