Recommand · June 27, 2021 0

Add variables from user input fields

 var c7 = document.getElementById("C7");
 var c8 = document.getElementById("C8");

function subtotal_conturi() {
   var c7_number = parseFloat(c7.value);
   if (isNaN(c7_number)) c7_number = 0;
   var c8_number = parseFloat(c8.value);
   if (isNaN(c8_number)) c8_number = 0;
  
  c10 = c7_number + c8_number;
   document.getElementById("subtotal-c10").value = c10;

   return c10;
}


 var c12 = document.getElementById("C12");
 var c13 = document.getElementById("C13");

 function subtotal_investitii() {
   var c12_number = parseFloat(c12.value);
   if (isNaN(c12_number)) c12_number = 0;
   var c13_number = parseFloat(c13.value);
   if (isNaN(c13_number)) c13_number = 0;

  c20 = c12_number + c13_number;
   document.getElementById("subtotal_c20").value = c20;

   return c20;
 }

 function add(c10,c20) {
   return c10+c20;
   console.log(add(c10,c20));
 }

I have 2 functions (c10 and c20) that represent the sum of some variables which I get from users (c10 is the sum of c7 and c8 input fields). I am trying to get the sum of c10 and c20. I removed ‘var’ from them so that I could access them globally but I stil cannot. How could I solve this?