Advertisement
dominornovus

Real-time total calculation using JavaScript

Jul 3rd, 2012
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.71 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Calculate total</title>
  6. <!--http://stackoverflow.com/a/11320760/835950-->
  7. <script type="text/javascript">
  8. function calc() {
  9.   var total = document.getElementById('q1').value + document.getElementById('q2').value;
  10.   document.getElememntById('total').value = total;
  11. }
  12. </script>
  13. </head>
  14.  
  15. <body>
  16. <input type="text" name="q1" id="q1" onChange="calc()">
  17. <input type="text" name="q2" id="q2" onChange="calc()">
  18. <input type="text" name="total" id="total">
  19. </body>
  20. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement