Professional Documents
Culture Documents
Pizza JS2
Pizza JS2
Pizza JS2
<head>
<script>
var size_9 = 0;
var size_12 = 0;
var size_14 = 0;
var stuff_no = 0;
var stuff_cheese = 0;
var stuff_sausage = 0;
function initializePage(){
function showTable(){
var myTable = document.getElementById("sales_list");
var defaultx = '<col width="50px"><col width="200px"><col
width="100px"><col width="80px"><col width="100px"><thead><tr><th> # </th><th>
Customer </th><th> Dine </th><th> Size </th><th> Stuffing </th></tr></thead>';
content = defaultx;
for (var x = 0; x < sales.length; x++){
content += "<tr>" +
"<td>" + x + "</td>" +
"<td>" + sales[x].name + "</td>" +
"<td>" + sales[x].dine + "</td>" +
"<td>" + sales[x].size + "</td>" +
"<td>" + sales[x].stuff + "</td>" +
"</tr>";
}
myTable.innerHTML = "</table>" + content;
// alert(content);
function addOrder(){
var id = 0;
var cName = document.getElementById("tbxName");
var cDine = document.querySelector("input[name='dine']:checked");
var cSize = document.querySelector("input[name='pizzaSize']:checked");
var cCrust = document.querySelector("input[name='stuff']:checked");
customer = cName.value;
dine = cDine.value;
size = cSize.value;
cCrust = cCrust.value;
if (cCrust = "No"){
stuff_no++;
}else if (cCrust = "Cheese"){
stuff_cheese++
}
else{
stuff_sausage++;
}
var sale={
"id": id,
"name": customer,
"dine": dine,
"size": size,
"stuff": cCrust,
};
var size={
"9in": size_9,
"12in": size_12,
"14in": size_14,
};
var stuff={
"No": stuff_no,
"Cheese": stuff_cheese,
"Sausage": stuff_sausage,
};
sales.push(sale);
sizes.push(size);
showTable();
function resetOrder(){
var myTable = document.getElementById("sales_list");
var defaultx = '<col width="50px"><col width="200px"><col
width="100px"><col width="80px"><col width="100px"><thead><tr><th> # </th><th>
Customer </th><th> Dine </th><th> Size </th><th> Stuffing </th></tr></thead>';
var newcontent = defaultx + "</table>";
myTable.innerHTML = newcontent;
sales = [];
sizes = [];
stuffings = [];
size_9 = 0;
size_12 = 0;
size_14 = 0;
stuff_no = 0;
stuff_cheese = 0;
stuff_sausage = 0;
</script>
<style>
.userInput{
background-color: #f5f5f5;
margin-left: auto;
margin-right: auto;
padding: 10px;
width: 500px;
}
.text-align-center{
text-align: center;
}
.text-align-left{
text-align: left;
}
.margin-lr-auto{
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body onload="initializePage()">
<hr/>
<div class="userInput">
<tr>
<td class="text-align-left"><label> Pizza Size </label></td>
<td class="text-align-left">
<input type="radio" id="rad9In" name="pizzaSize" value="9 in" checked>
<label for="rad9In"> 9 In </label>
<input type="radio" id="rad12In" name="pizzaSize" value="12 in">
<label for="rad12In"> 12 In </label>
<input type="radio" id="rad14In" name="pizzaSize" value="14 in">
<label for="rad14In"> 14 In </label>
</td>
</tr>
<tr>
<td class="text-align-left"><label> Stuff Crust </label></td>
<td class="text-align-left">
<input type="radio" id="radNo" name="stuff" value="No" checked>
<label for="radNo"> No </label>
<input type="radio" id="radCheese" name="stuff" value="Cheese">
<label for="radCheese"> Cheese </label>
<input type="radio" id="radSausage" name="stuff" value="Sausage">
<label for="radSausage"> Sausage </label>
</td>
</tr>
<tr>
<td>
<input type="button" value="Add to list" onclick="addOrder()">
<input type="button" value="Reset List" onClick="resetOrder()">
</td>
<td></td>
</tr>
</table>
</div>
<hr/>
<div id="size_content">
<p style="text-align: center"> Sizes Summary </p>
<table id="sizes_summary" border="1px solid black" class="margin-lr-auto">
<col width="430px">
<col width="100px">
<tr>
<td> 9 In </td>
<td> 0 </td>
</tr>
<tr>
<td> 12 In </td>
<td> 0 </td>
</tr>
<tr>
<td> 14 In </td>
<td> 0 </td>
</tr>
</table>
</div>
<div id="stuff_content">
<p style="text-align: center"> Stuffings Summary </p>
<table id="stuffings_summary" border="1px solid black" class="margin-lr-
auto">
<col width="430px">
<col width="100px">
<tr>
<td> No </td>
<td> 0 </td>
</tr>
<tr>
<td> Cheese </td>
<td> 0 </td>
</tr>
<tr>
<td> Sausage </td>
<td> 0 </td>
</tr>
</table>
</div>
</body>
</html>