I have XML request which returns table of menu like shown in 1st table. Here is my code snippet:
HTML
<body>
<h1>Food Menu</h1>
<button type="button" onclick="simpleXML()">Show the Menu</button>
<br><br>
<table id="menu-table"></table>
<br>
<div id="btn2"></div>
<br>
<table id="menu-count-table"></table>
<br><br>
<script src="script.js"></script>
</body>
JS
function simpleXML() {
const xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
menu(this);
}
};
xmlhttp.open("GET", "https://www.w3schools.com/xml/simple.xml", true);
xmlhttp.send();
}
function menu(xml) {
let i;
let xmlDoc = xml.responseXML;
let menuTable="<tr><th>name</th><th>price</th><th>description</th><th>calories</th></tr>";
let x = xmlDoc.getElementsByTagName("food");
for (i = 0; i <x.length; i++) {
menuTable += "<tr><td>" +
x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("calories")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("menu-table").innerHTML = menuTable;
const btn = document.createElement("button");
btn.innerHTML = "Make an order";
document.getElementById("btn2").appendChild(btn);
btn.onclick = function(){
simpleXML2();
};
}
My code returns xml doc like in 1st table in the photo and after clicking make an order it returns second table but without count and summary. How to add count summary rows?