Change the writing of an input text through JS

Asked

Viewed 540 times

0

I have an input field that receives the amount of products

 input type="number" class="form-control" min="0" max="5" id="pugQuant"  placeholder="0" onclick="calculo();"

And another that shows the calculated total. [total * value]

 input type="text" class="form-control" id="totalPug" name=""  value="1500.00" 
 disabled

I’m wanting to do the calculation with a function and show the value in the input but I don’t know how to modify with javascript. My function returns Nan.

function calculo(){
    var pugQuant = document.getElementById("pugQuant").value;

    document.getElementById("totalPug").value = 1500.00 * pugQuant.id;
}
  • Why are you using this . id in the pugQuant variable ?

  • Actually I saw on a website, but I pulled out and it worked

  • Way to go, buddy.

1 answer

1

I managed to solve..

Receives amount

 input type="number" class="form-control" min="0" max="5" id="pugQuant"  placeholder="0" onclick="calculo();"

Mostra Valor

input type="text" class="form-control" id="totalPug" name=""  value="1500.00" 
 disabled

Wrong function....

It contained wrong ". id"

function calculo(){
    var pugQuant = document.getElementById("pugQuant").value;

    document.getElementById("totalPug").value = 1500 * pugQuant.id;
}

Correct function...

function calculo(){
    var pugQuant = document.getElementById("pugQuant").value;

    document.getElementById("totalPug").value = 1500 * pugQuant;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.