fork(19) download
  1. <html>
  2. <title>jQuery Summing</title>
  3. <head>
  4. <script type="text/javascript" src="http://a...content-available-to-author-only...s.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script>
  5. $(document).ready(function() {
  6. $('.calc').on('input', function() {
  7. var t1 = document.getElementById('txt1');
  8. var t2 = document.getElementById('txt2');
  9. var tot=0;
  10. if (parseInt(t1.value))
  11. tot += parseInt(t1.value);
  12. if (parseInt(t2.value))
  13. tot += parseInt(t2.value);
  14. document.getElementById('txt3').value = tot;
  15. });
  16. });
  17. </script>
  18. </head>
  19. <body>
  20. <input type='text' class='calc' id='txt1'>
  21. <input type='text' class='calc' id='txt2'>
  22. <input type='text' id='txt3' readonly>
  23. </body>
  24. </html>
  25.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
<html>
	<title>jQuery Summing</title>
	<head>
		<script type="text/javascript" src="http://a...content-available-to-author-only...s.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script>
		$(document).ready(function() {
			$('.calc').on('input', function() {
				var t1 = document.getElementById('txt1');
				var t2 = document.getElementById('txt2');
				var tot=0;
				if (parseInt(t1.value))
					tot += parseInt(t1.value);
				if (parseInt(t2.value))
					tot += parseInt(t2.value);
				document.getElementById('txt3').value = tot;
			});
		});
		</script>
	</head>
	<body>
		<input type='text' class='calc' id='txt1'>
		<input type='text' class='calc' id='txt2'>
		<input type='text' id='txt3' readonly>
	</body>
</html>