JavaScript Trying to make a form that adds number automatically without submit like event listner

Please help I have done this so far. I want all 6 fiels working how can i do this? This is basically to calculate exam result so as fast help needed.

function myFunction() {
  var a = parseFloat(document.getElementById("txt1").value);
  var b = parseFloat(document.getElementById("txt2").value);
  var c = parseFloat(document.getElementById("txt3").value);
  var d = parseFloat(document.getElementById("txt3").value);
  var e = parseFloat(document.getElementById("txt4").value);
  var f = parseFloat(document.getElementById("txt5").value);
  var g = parseFloat(document.getElementById("txt6").value);
  var g = a + b + c + d + e + f + g;
  // If x = NaN empty variable x
  if (!g) {
    x = '';
  }
  document.getElementById("demo").innerHTML = x;
}
window.onload = function() {
  var inputs = document.getElementsByClassName('calc');
  for (var i = 0; i < inputs.length; i++) {
    // Listen for input > Call MyFunction
    inputs[i].addEventListener('input', myFunction, false);
  }
};
Enter first number:
<input type="text" class="calc" id="txt1" name="text1">Enter second number:
<input type="text" class="calc" id="txt2" name="text2">Enter third numve
<input type="text" class="calc" id="txt3" name="text3">Enter fourth number:
<input type="text" class="calc" id="txt4" name="text4">Enter fifth number:
<input type="text" class="calc" id="txt5" name="text5">Enter sixth number:
<input type="text" class="calc" id="txt6" name="text6">
<p id="demo"></p>
Answer:1

Since you have more inputs and you have expanded on my previous answer can cut down on the source code by using getElementsByClassName() and a for loop to add up the inputs.

Don't forget to close your inputs using />. I have also removed the ID's as the class name and for loop will take care of targeting those elements.

function myFunction() {
var a=0;
var Calc=document.getElementsByClassName('calc');
for(var i=0; i<Calc.length; i++){
	if(parseFloat(Calc[i].value)){
	a=a+parseFloat(Calc[i].value);
	}
}
// If a = NaN empty variable a
if(isNaN(parseFloat(a))){x='';}
// Changed from .innerHTML to .value
document.getElementById("Result").value = a;
}
window.onload=function(){
var inputs=document.getElementsByClassName('calc');
  for(var i=0; i<inputs.length; i++){
    // Listen for input > Call MyFunction
    inputs[i].addEventListener('input',myFunction,false);
  }
};
Enter first number: <input type="text" class="calc"/>
Enter second number:<input type="text" class="calc">
Enter third numve <input type="text" class="calc"/>
Enter fourth number:<input type="text" class="calc"/>
Enter fifth number: <input type="text" class="calc"/>
Enter sixth number:<input type="text" class="calc"/>
<!-- Div Removed and input added -->
<input type="text" id="Result"/>
Answer:2

I have a mean-stack website which enables html5mode by $locationProvider.html5Mode(true). and index.html looks like as follows: <html> <head> <base href="/" /> ... </head&...

I have a mean-stack website which enables html5mode by $locationProvider.html5Mode(true). and index.html looks like as follows: <html> <head> <base href="/" /> ... </head&...

var app = angular.module('myApp', ['ui.bootstrap']); app.controller('myCtrl', function($scope,$modal){ $scope.firstName = "John"; $scope.lastName = function(){ $modal.open({ ...

var app = angular.module('myApp', ['ui.bootstrap']); app.controller('myCtrl', function($scope,$modal){ $scope.firstName = "John"; $scope.lastName = function(){ $modal.open({ ...

I'm just starting out with Angular. I've written some code that downloads a JSON array configuredAPIs and displays each object within it, <div ng-repeat="capi in configuredAPIs">. For each of ...

I'm just starting out with Angular. I've written some code that downloads a JSON array configuredAPIs and displays each object within it, <div ng-repeat="capi in configuredAPIs">. For each of ...

  1. angular cheilitis
  2. angular velocity
  3. angular momentum
  4. angular acceleration
  5. angular speed
  6. angular material
  7. angular velocity formula
  8. angular js
  9. angular speed formula
  10. angular cli
  11. angular acceleration formula
  12. angular 9
  13. angular frequency
  14. angular momentum formula
  15. angular gyrus
  16. angular vs react
  17. angular tutorial
  18. angular interview questions
  19. angular momentum equation
  20. angular 8

I've never used scrollspy in my project and I need to know how it works. I have seen the documentation from the bootstrap page, some other stackoverflow questions and youtube videos. I have this code:...

I've never used scrollspy in my project and I need to know how it works. I have seen the documentation from the bootstrap page, some other stackoverflow questions and youtube videos. I have this code:...

  1. bootstrap scrollspy not working
  2. bootstrap scrollspy not working correctly
  3. bootstrap scrollspy not working in chrome
  4. bootstrap scrollspy not working in react
  5. bootstrap scrollspy active not working
  6. bootstrap scrollspy offset not working
  7. bootstrap 4 scrollspy not working
  8. bootstrap scrollspy data-offset not working
  9. bootstrap 3 scrollspy not working
  10. bootstrap scrollspy smooth scroll not working