[Solved] i want to sum 6 inputs and set the value to another input with javascript [closed]


Check the fiddle: https://jsfiddle.net/1qbjd36c/13/

$("form .form-control").not("#thesum").on("input", function() {
  var getSum = 0;
  $("form .form-control").not("#thesum").filter(function() { if($.isNumeric($(this).val())) return $(this).val();  }).each(function() {
  getSum+=parseFloat($(this).val());
  });
  $("#thesum").val(getSum);
});
  1. $("form .form-control") A tag and class selector has been utilized to reference the target.
  2. not("#thesum") added a not selector in order to avoid the change of input of Resulting TEXT field.
  3. on("input", function() { utilized ON-INPUT event, to trigger all input formats, which includes paste of clip text too.
  4. .filter(function() { utilized filter function to value only numeric values.
  5. getSum+=parseFloat($(this).val());, here use of + indicates summing upon with the previous value to the variable, in other words, recursive change on value, which returns the sum of all iterated values.

8

solved i want to sum 6 inputs and set the value to another input with javascript [closed]