Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions case1/mpl_links_txt.html → case1/mpl_links.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<meta charset="utf-8" />
<link href="mpl_base.css" rel="stylesheet" />
<link href="mpl_layout.css" rel="stylesheet" />
<script src="mpl_links.js"></script>
</head>

<body>
Expand Down
26 changes: 26 additions & 0 deletions case1/mpl_links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

/*
New Perspectives on HTML5, CSS3, and JavaScript 6th Edition
Tutorial 13
Case Problem 1

Author:
Date:

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;
}
}
});


15 changes: 0 additions & 15 deletions case1/mpl_links_txt.js

This file was deleted.

9 changes: 5 additions & 4 deletions case2/dl_expense_txt.html → case2/dl_expense.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<meta charset="utf-8" />
<link href="dl_base.css" rel="stylesheet" />
<link href="dl_layout.css" rel="stylesheet" />
<script src="dl_expese.js" async> </script>


</head>
Expand Down Expand Up @@ -70,20 +71,20 @@ <h1>Expense Report</h1>
<th>First Name<span>*</span></th>
<th>M.I.</th>
<th>Account<span>*</span></th>
<td><input type="text" name="accID" id="accID" placeholder="ACTnnnnnn" required /></td>
<td><input type="text" name="accID" id="accID" placeholder="ACTnnnnnn" pattern="ACT\d{6}" required /></td>
</tr>
<tr>
<td><input type="text" name="lname" id="lname" required /></td>
<td><input type="text" name="fname" id="fname" required /></td>
<td><input type="text" name="init" id="init" required /></td>
<th>Department<span>*</span></th>
<td><input type="text" name="deptID" id="deptID" required placeholder="DEPTnnnnnn" /></td>
<td><input type="text" name="deptID" id="deptID" pattern="DEPT\d{4,6}" required placeholder="DEPTnnnnnn" /></td>
</tr>
<tr>
<th>Social Security Number<span>*</span></th>
<td colspan="2"><input type="text" name="ssn" id="ssn" required placeholder="nnn-nn-nnnn" /></td>
<td colspan="2"><input type="text" name="ssn" id="ssn" pattern="\d{3}-\d{2}-\d{4}" required placeholder="nnn-nn-nnnn" /></td>
<th>Project<span>*</span></th>
<td><input type="text" name="projID" id="projID" required placeholder="PROJ-xx-ddd" /></td>
<td><input type="text" name="projID" id="projID" pattern="PROJ-\D[a-z]-\d{4}"required placeholder="PROJ-xx-ddd" /></td>
</tr>
</table>

Expand Down
95 changes: 95 additions & 0 deletions case2/dl_expense.js
Original file line number Diff line number Diff line change
@@ -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"} );
}
48 changes: 0 additions & 48 deletions case2/dl_expense_txt.js

This file was deleted.

2 changes: 1 addition & 1 deletion case3/mas_reg2_txt.html → case3/mas_reg2.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<title>MAS Registration Payment Form</title>
<link href="mas_base.css" rel="stylesheet" />
<link href="mas_styles.css" rel="stylesheet" />
>
<script src="mas_reg2.js" async></script>
</head>

<body>
Expand Down
36 changes: 36 additions & 0 deletions case3/mas_reg2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use strict";
/*
New Perspectives on HTML5, CSS3, and JavaScript 6th Edition
Tutorial 13
Case Problem 3


Filename: mas_reg2.js

Author: Gary Unwin
Date: 2018-03-01


Function List
=============

writeSessionValues()
Writes data values from session storage in to the
registration summary form


*/

window.addEventListener("load", writeSessionValues);

function writeSessionValues() {

document.getElementById("regName").textContent = sessionStorage.confName;
document.getElementById("regGroup").textContent = sessionStorage.confGroup;
document.getElementById("regEmail").textContent = sessionStorage.confMail;
document.getElementById("regPhone").textContent = sessionStorage.confPhone;
document.getElementById("regSession").textContent = sessionStorage.confSession;
document.getElementById("regBanquet").textContent = sessionStorage.confBanquet;
document.getElementById("regPack").textContent = sessionStorage.confPack;
document.getElementById("regTotal").textContent = "$" + sessionStorage.confTotal;
}
23 changes: 0 additions & 23 deletions case3/mas_reg2_txt.js

This file was deleted.

1 change: 1 addition & 0 deletions case3/mas_register_txt.html → case3/mas_register.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<title>MAS Registration Form</title>
<link href="mas_base.css" rel="stylesheet" />
<link href="mas_styles.css" rel="stylesheet" />
<script src="mas_register.js" async></script>

</head>

Expand Down
Loading