Can I pass a result from a percentage calculation in JavaScript?

0

The calculation I was able to do with JavaScript, but the output of it has to be in percentage.

<script>
var mb = document.querySelector("input[name=medidab]");
mb.addEventListener("keyup", calcImc, false);
function calcImc(){
   var md_val = parseFloat(mb.value);
   medidab = (md_val/50*100).toFixed(1);
   if(!isNaN(medidab)){
      document.querySelector("input[name=circunferenciabraco]").value = medidab;
   }
}
</script>

And here and the form, I put the value in one field and the value of the calculation already comes out in the other one. It just has to come out in percentage and I do not know if it's possible.

<div>
   <input class="campo-form-c" type="text" name="medidab" placeholder="Medida do Braço" maxlength="5">
</div>
<div>
   <input class="campo-form-c" type="text" name="circunferenciabraco" placeholder="Circunferência do Braço" maxlength="5"></br>
</div>
    
asked by anonymous 15.11.2017 / 06:37

1 answer

1

As you have already been able to calculate, simply concatenate % into the result:

document.querySelector("input[name=circunferenciabraco]").value = medidab+"%";

var mb = document.querySelector("input[name=medidab]");
mb.addEventListener("keyup", calcImc, false);
function calcImc(){
   var md_val = parseFloat(mb.value);
   medidab = (md_val/50*100).toFixed(1);
   if(!isNaN(medidab)){
      document.querySelector("input[name=circunferenciabraco]").value = medidab+"%";
   }
}
<div>
   <input class="campo-form-c" type="text" name="medidab" placeholder="Medida do Braço" maxlength="5">
</div>
<div>
   <input class="campo-form-c" type="text" name="circunferenciabraco" placeholder="Circunferência do Braço" maxlength="5"></br>
</div>
    
15.11.2017 / 07:17