I am trying to calculate the value and send it to the input. But it considers it as not 7.082 + 10 + 10, but simply adds 10 at the end, as if it were a text.

<script> function krsp() { var kolrap = document.getElementById('kolrap').value ; var priladka = document.getElementById('priladka').value ; var procent = document.getElementById('procent').value; document.getElementById('kolrsp').value = document.getElementById('kolrap').value * document.getElementById('procent').value / 100 + (document.getElementById('kolrap').value + document.getElementById('priladka').value) ; } </script> 
  • one
    And why do you get variables if you don’t use them in the future and try to carry out the calculation through .value? - Legionary
  • html code add - stackanon
  • Try explicitly converting input values ​​to parseFloat (document.getElementById ('kolrap'). value) - akrasnov87
  • And what is better to calculate? - Big Daddy
  • Conversion helped, thanks! - Big Daddy

1 answer 1

You add string and not a number.

 function krsp() { var kolrap = parseFloat(document.getElementById('kolrap').value); var priladka = parseFloat(document.getElementById('priladka').value); var procent = parseFloat(document.getElementById('procent').value); document.getElementById('kolrsp').value = kolrap * procent / 100 + kolrap + priladka; }