SHARE
TWEET

homework

a guest Sep 13th, 2017 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <! DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="UTF-8"/>
  5.         <title>Testside</title>
  6.         <script>
  7.             window.onload = oppstart;
  8.             var totalAmount = 0;
  9.            
  10.             function oppstart(){
  11.                 document.getElementById("btnVare").onclick = visVare;
  12.             }
  13.  
  14.             function visVare(){
  15.                 var vare = document.getElementById("vare").value,
  16.                     antallVare = document.getElementById("antallVare").value;
  17.                 document.getElementById("handleliste").innerHTML = document.getElementById("handleliste").innerHTML +
  18.                 "<li>" + vare + " " + antallVare + "</li>";
  19.  
  20.                 totalAmount += parseInt(antallVare);
  21.  
  22.                 console.log(totalAmount);
  23.  
  24.                 document.getElementById("totalAmount").innerHTML = "Total amount: " + totalAmount;
  25.             }
  26.         </script>
  27.     </head>
  28.  
  29.     <body>
  30.         <p>Antall <input id="antallVare" type="text"></input></br></p>
  31.         <p>Vare <input id="vare" type="text"></input></br></p>
  32.         <button id="btnVare" type="button">Legg til vare!</button>
  33.         <ul id="handleliste">
  34.         </ul>
  35.  
  36.         <p id="totalAmount"> </p>
  37.     </body>
  38. </html>
RAW Paste Data
Top