-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw3part2.html
More file actions
186 lines (170 loc) · 7.15 KB
/
hw3part2.html
File metadata and controls
186 lines (170 loc) · 7.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html lang="en">
<head>
<!--Kristian Reyes 9/26/2020 -->
<title>CNIT 133 Homework 3</title>
<meta charset="utf-8">
<meta name="description" content="homework 3 for CCSF CNIT 133">
<meta name="keywords" content="HTML, CSS, Javascript, CCSF, Student">
<meta name="author" content="Kristian Reyes">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<!--bootstrap -->
<!-- jquery validation -->
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!-- jquery validation -->
<script>
<!-- // $(document).ready(function(){ -->
// $("#myform").validate({
// // Rules for each input item
// // rules:
// {
// item1: { required: true, number: true },
// item2: { required: true, number: true },
// item3: { required: true, number: true },
// item4: { required: true, number: true },
// }
// });
function itemCalc() {
// if ($("#myform").valid()) {
event.preventDefault();
var item1 = parseInt(document.getElementById("item1").value);
var item2 = parseInt(document.getElementById("item2").value);
var item3 = parseInt(document.getElementById("item3").value);
var item4 = parseInt(document.getElementById("item4").value);
var errMsg = "<span style='font-weight: bold; color: red; font-size: 20px;'> Input is invalid. Only enter positive integers.</span>";
if (isNaN(item1) || isNaN(item2) || isNaN(item3) || isNaN(item4) || item1 < 0 || item2 < 0 || item3 < 0 || item4 < 0 )
document.getElementById("inputErr").innerHTML = errMsg;
else{
var item1tot = (item1 * 239.99).toFixed(2);
var item2tot = (item2 * 129.75).toFixed(2);
var item3tot = (item3 * 239.99).toFixed(2);
var item4tot = (item4 * 350.89).toFixed(2);
var totamount = item1 + item2 + item3 + item4;
var totearn = parseInt(item1tot) + parseInt(item2tot) + parseInt(item3tot) + parseInt(item4tot);
totearn = totearn.toFixed(2)
document.getElementById("tally1").innerHTML = item1;
document.getElementById("total1").innerHTML = "$" + item1tot;
document.getElementById("tally2").innerHTML = item2;
document.getElementById("total2").innerHTML = "$" + item2tot;
document.getElementById("tally3").innerHTML = item3;
document.getElementById("total3").innerHTML = "$" + item3tot;
document.getElementById("tally4").innerHTML = item4;
document.getElementById("total4").innerHTML = "$" + item4tot;
document.getElementById("grandtotal").innerHTML = totamount;
document.getElementById("grandearnings").innerHTML = "$" + totearn;
}
}
</script>
<style>
.r {text-align: right;}
</style>
<body>
<main class="grid">
<header class="grid-area grid-area-1">
<h2> Homework 3 - Part 2 </h2>
</header>
<nav class="grid-area grid-area-2">
<ul>
<li>
<a href="homework3.html" title="CNIT 133 - HW 3">
Return to CNIT 133 Homework 3 - Functions
</a>
</li>
</ul>
</nav>
<section class="grid-area grid-area-3">
<h1> HW 3 - Part 2 </h1>
<h2> Sales Commissions </h2>
<label for="salesname">Salesperson's Name:</label>
<input id="salesname" name="salesname" title="Please make sure that the salesperson's name is spelled correctly.">
<br>
<div id ="inputErr"></div>
<br>
<br>
<form name="itemtally">
<table>
<tr>
<td>Item 1:</td>
<td><input class="r" id="item1" type="number" ></td>
</tr>
<tr>
<td>Item 2:</td>
<td><input class="r" id="item2" type="number" ></td>
</tr>
<tr>
<td>Item 3:</td>
<td><input class="r" id="item3" type="number" ></td>
</tr>
<tr>
<td>Item 4:</td>
<td><input class="r" id="item4" type="number" ></td>
</tr>
</table>
<br>
<button onclick="itemCalc()">Submit</button>
<input type="reset" value="reset" onclick="location.reload()">
<br>
<br>
</form>
<p> Input the number of items sold for each item number:</p>
<table id ="totaltally">
<tr>
<th> Item # </th>
<th> Price </th>
<th> Number Sold </th>
<th> </th>
<th>Total</th>
</tr>
<tr>
<td> 1 </td>
<td> $239.99 </td>
<td class="r" id = "tally1" > </td>
<td></td>
<td class="r" id = "total1" > </td>
</tr>
<tr>
<td>2</td>
<td> $129.75 </td>
<td class="r" id = "tally2" > </td>
<td></td>
<td class="r" id = "total2" > </td>
</tr>
<tr>
<td> 3 </td>
<td> $99.95 </td>
<td class="r" id = "tally3" > </td>
<td></td>
<td class="r" id = "total3" > </td>
</tr>
<tr>
<td> 4 </td>
<td> $350.89 </td>
<td class="r" id = "tally4" > </td>
<td></td>
<td class="r" id = "total4" > </td>
</tr>
<tr>
<td>Total Amount Sold</td>
<td class="r" id="grandtotal"></td>
</tr>
<tr>
<td>Total Weekly Earnings</td>
<td class="r" id="grandearnings"></td>
</tr>
</table>
</section>
<footer class="grid-area grid-area-4">
<p>
© 2020 Kristian Reyes
</p>
</footer>
</main>
</body>
</html>