Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Calorie Count</title>
- <script>
- function $(id) {return document.getElementById(id)}
- window.addEventListener('load', function() {
- $('show').addEventListener('click', function() {$('result').innerHTML = '<strong>Food:</strong> '+localStorage.getItem('food')+'<br /><strong>Calories:</strong>'+localStorage.getItem('calories');});
- $('form').addEventListener('submit', function() {
- localStorage.setItem('food', $('food').value);
- localStorage.setItem('calories', $('calories').value);
- });
- });
- </script>
- </head>
- <body>
- <h1>Kilo</h1>
- <div>
- <h2>New Entry</h2>
- <form id="form" onsubmit="return false;">
- <label><input type="text" placeholder="Food" name="food" id="food" /></label><br />
- <label><input type="text" placeholder="Calories" name="calories" id="calories" /></label><br />
- <input type="submit" value="Save" />
- </form>
- <button id="show">Show</button>
- <h2>Result</h2>
- <div id="result"></div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement