Advertisement
achshar

Untitled

May 7th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>Calorie Count</title>
  5.         <script>
  6.             function $(id) {return document.getElementById(id)}
  7.             window.addEventListener('load', function() {               
  8.                 $('show').addEventListener('click', function() {$('result').innerHTML = '<strong>Food:</strong> '+localStorage.getItem('food')+'<br /><strong>Calories:</strong>'+localStorage.getItem('calories');});
  9.                 $('form').addEventListener('submit', function() {
  10.                     localStorage.setItem('food', $('food').value);
  11.                     localStorage.setItem('calories', $('calories').value);
  12.                 });
  13.             });
  14.         </script>
  15.     </head>
  16.     <body>
  17.         <h1>Kilo</h1>
  18.         <div>
  19.             <h2>New Entry</h2>
  20.             <form id="form" onsubmit="return false;">
  21.                 <label><input type="text" placeholder="Food" name="food" id="food" /></label><br />
  22.                 <label><input type="text" placeholder="Calories" name="calories" id="calories" /></label><br />
  23.                 <input type="submit" value="Save" />
  24.             </form>
  25.             <button id="show">Show</button>
  26.             <h2>Result</h2>
  27.             <div id="result"></div>
  28.         </div>
  29.     </body>
  30. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement