Pizza JS2

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

<html>

<head>
<script>

var sales = [];


var sizes = [];
var stuffings = [];

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

var defaulty = '<table id="sales_list" border="1px solid black"


class="margin-lr-auto"><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></table></table><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> ' + size_9 + '
</td></tr><tr><td> 12 In </td><td> '+ size_12 + ' </td></tr><tr><td> 14 In
</td><td> ' + size_12 + ' </td></tr></table>';

var myTable = document.getElementById("sales_list");


var myTable2 = document.getElementById("sizes_summary");
}

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 (dine = "9 in"){


size_9++;
}else if (dine = "12 in"){
size_12++
}
else{
size_14++;
}

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">

<!-- USER INPUT -->


<table>
<tr>
<td class="text-align-left"><label> Customer </label></td>
<td class="text-align-left"><label><input type="String"
id="tbxName"></label></td>
</tr>
<tr>
<td class="text-align-left"><label> Dine </label></td>
<td class="text-align-left">
<input type="radio" id="radDineIn" name="dine" value="Dine in" checked>
<label for="radDineIn"> Dine-in </label>
<input type="radio" id="radTakeOut" name="dine" value="Take out">
<label for="radTakeOut"> Take out </label>
</td>
</tr>

<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/>

<!-- SALES LIST -->


<div>
<p style="text-align: center"> Sales List </p>
<table id="sales_list" border="1px solid black" class="margin-lr-auto">
<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>
</table>
</table>

<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>

You might also like