View difference between Paste ID: gQZGV2SL and XemGA6wL
SHOW: | | - or go back to the newest paste.
1
<!DOCTYPE html>
2
<html>
3-
    <head>
3+
	<head>
4-
        <title>Calorie Count</title>
4+
		<title>Calorie Count</title>
5-
    </head>
5+
		<script>
6-
    <body >
6+
			function $(id) {return document.getElementById(id)}
7-
         <div id="home">
7+
			window.addEventListener('load', function() {				
8-
         	<h1>Kilo</h1>
8+
				$('show').addEventListener('click', function() {$('result').innerHTML = '<strong>Food:</strong> '+localStorage.getItem('food')+'<br /><strong>Calories:</strong>'+localStorage.getItem('calories');});
9-
         	<h2>New Entry</h2>
9+
				$('form').addEventListener('submit', function() {
10-
         <form method="post">
10+
					localStorage.setItem('food', $('food').value);
11-
         	<ul>
11+
					localStorage.setItem('calories', $('calories').value);
12-
                    <li><input type="text" placeholder="Food" name="food" id="food" required></li>
12+
				});
13-
                    <li><input type="text" placeholder="Calories" name="calories" id="calories" required></li>
13+
			});
14-
                    <li><input type="submit" id="submit" value="Save" /></li>
14+
		</script>
15-
		    <li><input type="submit" id="show" value="Show" /></li>
15+
	</head>
16-
                </ul>
16+
	<body>
17-
         </form>
17+
		<h1>Kilo</h1>
18-
        </div>
18+
		<div>
19-
	<script>
19+
			<h2>New Entry</h2>
20-
		var link = document.getElementById("submit");
20+
			<form id="form" onsubmit="return false;">
21-
		var tes = document.getElementById("show");
21+
				<label><input type="text" placeholder="Food" name="food" id="food" /></label><br />
22-
		link.addEventListener('click', function () {
22+
				<label><input type="text" placeholder="Calories" name="calories" id="calories" /></label><br />
23-
		localStorage.setItem('food', food.value);
23+
				<input type="submit" value="Save" />
24-
		localStorage.setItem('calories', calories.value);
24+
			</form>
25-
		}, false);
25+
			<button id="show">Show</button>
26-
		tes.addEventListener('click', function tes(){
26+
			<h2>Result</h2>
27-
		console.log(localStorage.getItem("food")+ " " +localStorage.getItem("calories"));
27+
			<div id="result"></div>
28-
		localStorage.clear();
28+
		</div>
29-
		}, false);
29+
	</body>
30-
</script>
30+