diff --git a/case1/mpl_links_txt.html b/case1/mpl_links.html similarity index 97% rename from case1/mpl_links_txt.html rename to case1/mpl_links.html index 956d056..efa5765 100644 --- a/case1/mpl_links_txt.html +++ b/case1/mpl_links.html @@ -17,6 +17,7 @@ +
diff --git a/case1/mpl_links.js b/case1/mpl_links.js new file mode 100644 index 0000000..da98a17 --- /dev/null +++ b/case1/mpl_links.js @@ -0,0 +1,24 @@ +"use strict"; + +/* + New Perspectives on HTML5, CSS3, and JavaScript 6th Edition + Tutorial 13 + Case Problem 1 + + Author: Denise Kruschev + Date: 2018-03-01 + + Filename: mpl_links.js + +*/ + + +window.addEventListener("load", function() { + var allSelect = document.querySelectorAll("form#govLinks select"); + + for (var i = 0; i < allSelect.length; i++) { + allSelect[i].onchange = function(e) { + location.href = e.target.value; + } + } +}); \ No newline at end of file diff --git a/case1/mpl_links_txt.js b/case1/mpl_links_txt.js deleted file mode 100644 index fe21beb..0000000 --- a/case1/mpl_links_txt.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; - -/* - New Perspectives on HTML5, CSS3, and JavaScript 6th Edition - Tutorial 13 - Case Problem 1 - - Author: - Date: - - Filename: mpl_links.js - -*/ - - diff --git a/case2/dl_expense_txt.html b/case2/dl_expense.html similarity index 96% rename from case2/dl_expense_txt.html rename to case2/dl_expense.html index 48fadef..2bd11ab 100644 --- a/case2/dl_expense_txt.html +++ b/case2/dl_expense.html @@ -17,7 +17,7 @@ - + diff --git a/case2/dl_expense.js b/case2/dl_expense.js new file mode 100644 index 0000000..5d1bee8 --- /dev/null +++ b/case2/dl_expense.js @@ -0,0 +1,95 @@ +"use strict"; + +/* + New Perspectives on HTML5, CSS3, and JavaScript 6th Edition + Tutorial 13 + Case Problem 2 + + Author: Kay Ramirez + Date: 2018-03-01 + + Filename: dl_expense.js + + Function List + ============= + + validateSummary() + Validates the data entry in the summary field. + + calcClass(sumClass) + Sums up all of the data values for elements of the sumClass class. + + calcExp() + Calculates the travel expenses from all categories and dates. + + formatNumber(val, decimals) + Formats the value, "val" to the number of decimals indicated + by "decimals", adding thousands separators. + + formatUSCurrency(val) + Formats the value, "val", as U.S. currency. + +*/ + +window.addEventListener("load", function() { + var changingCells = document.querySelectorAll("table#travelExp input.sum"); + + for (var i = 0; i < changingCells.length; i++) { + changingCells[i].onchange = calcExp; + } + + document.getElementById("submitButton").onclick = function() { + validateSummary(); + }; +}); + +function validateSummary() { + var summary = document.getElementById("summary"); + if (summary.validity.valueMissing) { + summary.setCustomValidity("You must include a summary of the trip in your report."); + } else { + summary.setCustomValidity(""); + } +} + +function calcClass(sumClass) { + var sumFields = document.getElementsByClassName(sumClass); + var sumTotal = 0; + + for (var i=0; i < sumFields.length; i++) { + var itemValue = parseFloat(sumFields[i].value); + if (!isNaN(itemValue)) { + sumTotal += itemValue; + } + } + return sumTotal; +} + + +function calcExp() { + + var expTable = document.querySelectorAll("table#travelExp tbody tr"); + + for (var i = 0; i < expTable.length; i++) { + document.getElementById("subtotal"+i).value = formatNumber(calcClass("date"+i), 2); + } + + document.getElementById("transTotal").value = formatNumber(calcClass("trans"), 2); + document.getElementById("lodgeTotal").value = formatNumber(calcClass("lodge"), 2); + document.getElementById("mealTotal").value = formatNumber(calcClass("meal"), 2); + document.getElementById("otherTotal").value = formatNumber(calcClass("other"), 2); + document.getElementById("expTotal").value = formatUSCurrency(calcClass("sum")); +} + + + + + +function formatNumber(val, decimals) { + return val.toLocaleString(undefined, {minimumFractionDigits: decimals, + maximumFractionDigits: decimals}); +} + +function formatUSCurrency(val) { + return val.toLocaleString('en-US', {style: "currency", currency: "USD"} ); +} \ No newline at end of file diff --git a/case2/dl_expense_txt.js b/case2/dl_expense_txt.js deleted file mode 100644 index bc32b41..0000000 --- a/case2/dl_expense_txt.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; - -/* - New Perspectives on HTML5, CSS3, and JavaScript 6th Edition - Tutorial 13 - Case Problem 2 - - Author: - Date: - - Filename: dl_expenses.js - - Function List - ============= - - validateSummary() - Validates the data entry in the summary field. - - calcClass(sumClass) - Sums up all of the data values for elements of the sumClass class. - - calcExp() - Calculates the travel expenses from all categories and dates. - - formatNumber(val, decimals) - Formats the value, "val" to the number of decimals indicated - by "decimals", adding thousands separators. - - formatUSCurrency(val) - Formats the value, "val", as U.S. currency. - -*/ - - - - - - - - -function formatNumber(val, decimals) { - return val.toLocaleString(undefined, {minimumFractionDigits: decimals, - maximumFractionDigits: decimals}); -} - -function formatUSCurrency(val) { - return val.toLocaleString('en-US', {style: "currency", currency: "USD"} ); -} \ No newline at end of file diff --git a/case3/mas_reg2_txt.html b/case3/mas_reg2.html similarity index 96% rename from case3/mas_reg2_txt.html rename to case3/mas_reg2.html index 63ca91a..34f633b 100644 --- a/case3/mas_reg2_txt.html +++ b/case3/mas_reg2.html @@ -19,6 +19,7 @@