1
How can I pick up the correspondent to earnings
in JSON (Value 0€
) and output in Javascript?
That is, so that on the website the corresponding to Earnings
(0€) in what I identified as OUTPUT DE EARNINGS AQUI
in Javascript.
JSON
{
"DataInfo":[
{
"Earnings": "0€",
"Orders": "0"
}
]
}
JS
function Earnings() {
var ElementEarnings = document.getElementById("Earnings");
ElementEarnings.innerHTML = OUTPUT DE EARNINGS AQUI (0€);
}
WEBSITE
function Earnings() {
var ElementEarnings = document.getElementById("Earnings");
ElementEarnings.innerHTML = "OUTPUT DE EARNINGS AQUI (0€)";
}
function Orders() {
var ElementOrders = document.getElementById("Orders")
ElementOrders.innerHTML = "1";
}
function JSONLOAD() {
"use stric";
fetch("Static/Data/DATA.json")
.then(function(resp) {
return resp.json();
})
.then(function(data){
var Earnings = data.Earnings;
var Orders = data.Orders;
console.log(data);
})
}
Earnings()
Orders()
JSONLOAD()
body {
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
margin-bottom: 0px;
background: #252C35;
color: white;
}
#UpperBar {
height: 45px;
}
.MASlime {
position: absolute;
font-size: 30px;
top: 1px;
left: 40px;
}
#Totals {
position: absolute;
font-size: 30px;
}
.Total {
position: absolute;
top: 70px;
left: 130px;
}
.TotalEarnings {
position: absolute;
top: 70px;
left: 200px;
}
.TotalO {
position: absolute;
top: 140px;
left: 130px;
}
.TotalOrders {
position: absolute;
top: 140px;
left: 200px;
}
#Earnings {
position: absolute;
top: 70px;
left: 350px;
}
#Orders {
position: absolute;
top: 140px;
left: 350px;
}
.NewOrder {
position: absolute;
top: 250px;
left: 200px;
font-size: 30px;
}
.OrderName {
position: absolute;
top: 350px;
left: 140px;
width: 250px;
height: 25px;
background-color: #252C35;
color: white;
border: 1px;
border-style: solid;
border-radius: 5px;
border-color: white;
padding: 5px;
}
.OrderDate {
position: absolute;
top: 400px;
left: 140px;
width: 250px;
height: 25px;
background-color: #252C35;
color: white;
border: 1px;
border-style: solid;
border-radius: 5px;
border-color: white;
padding: 5px;
}
.SKU {
position: absolute;
top: 450px;
left: 140px;
width: 250px;
height: 25px;
background-color: #252C35;
color: white;
border: 1px;
border-style: solid;
border-radius: 5px;
border-color: white;
padding: 5px;
}
.SUBMIT {
position: absolute;
top: 500px;
left: 220px;
width: 100px;
height: 40px;
background-color: #252C35;
color: white;
border: 1px;
border-style: solid;
border-radius: 5px;
border-color: white;
padding: 5px;
}
.Menu {
position: absolute;
top: 25px;
left: 480px;
font-size: 30px;
cursor: pointer;
}
.menu {
text-align: center;
width: 100%;
}
.menu a {
display: block;
border-bottom: 1px solid #EAEAED;
border-top: 1px solid #EAEAED;
text-decoration: none;
color: white;
margin-top: 120px;
padding-bottom: 10px;
padding-top: 10px;
font-size: 30px;
background: #252C35;
}
.All {
display: block;
}
#toggle {
display: none;
}
.fadeIn {
animation: fadein 1.3s ease-in;
}
@keyframes fadein {
0% { opacity: 0; }
25% { opacity: 0.3; }
50% { opacity: 0.5; }
75% { opacity: 0.8; }
100% { opacity: 1; }
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>EComerce App Slime</title>
<link rel="stylesheet" href="Static/css/index.css">
</head>
<body>
<div id="menu">
<label for="toggle" class="Menu">☰</label>
<input type="checkbox" id="toggle" onclick="meuMenuToggle()"/>
<div class="menu">
<a href="#">Slime Recipe</a>
</div>
</div>
<div id="UpperBar">
<p class="MASlime">MASlime</p>
</div>
<div id="HomePage">
<div id="Totals">
<p class="Total">Total</p>
<p class="TotalEarnings">Earnings</p>
<p class="TotalO">Total</p>
<p class="TotalOrders">Orders</p>
<p id="Earnings">100€</p>
<p id="Orders">1</p>
</div>
<div id="NewOrder">
<p class="NewOrder">New Order</p>
<form id="OrderForm">
<input class="OrderName" type="text" name="OrderName" placeholder="Buyer Name" required>
<input class="OrderDate" type="text" name="OrderDate" placeholder="Date of Order" required>
<input class="SKU" type="text" name="ProductSKU" placeholder="Product SKU" required>
<input class="SUBMIT" type="button" name="Submit" value="SUBMIT">
</form>
</div>
</div>
<script>
var home = document.getElementById('HomePage');
var menu = document.getElementsByClassName('menu')[0];
menu.style.display = 'none';
document.getElementById('toggle').onclick = () => {
if (menu.style.display == 'none') setTimeout(fadeMenu, 150);
else if(menu.style.display == 'block') setTimeout(fadeHome, 150);
}
function fadeMenu() {
home.style.display = 'none';
menu.classList.add('fadeIn');
menu.style.display = 'block';
}
function fadeHome() {
home.style.display = 'block';
home.classList.add('fadeIn');
menu.style.display = 'none';
}
</script>
<script src="Static/js/index.js"></script>
</body>
</html>
I put it this way : https://pastebin.com/g081zmAv But he is saying in the cosola this
Uncaught SyntaxError: Unexpected token . index.js:18
– user132381
@hkotsubo I put it this way : Pastebin.com/g081zmAv But he is saying in the cosola this Uncaught Syntaxerror: Unexpected token . index.js:18
– user132381
@Deadsec I did not test, but in a quick look, missed the parameter in the first function:
function appendOrders(orders)
, and further down isuse strict
("t" was missing). But maybe there is another error in other parts of the code, because testing only with what you passed, I had no syntax error...– hkotsubo
@hkotsubo All problems have been solved Thank you!
– user132381
@Deadsec If one of the answers solved your problem, you can choose the one that best solved it and accept it, see here how and why to do it. It’s not mandatory, but it’s good site practice to indicate to future visitors that it solved the problem (but if you think none of them actually solved it, then you don’t have to accept any). Don’t forget that you can also vote in all the answers you found useful.
– hkotsubo