Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
javascript multiply 2 number show total and gtotal but show only one value?

I am using javascript calculation. multiply 2 numbers: number 1 * number 2 = total and how g-total but working only one value display?

I have need number 1 * number 2 = total and show Gtotal so please help and share a valuable idea...

HTML

<input
  name="per_hour"
  id="per_hour"
  class="form-control"
  value=""
  onblur="perhour()"
  placeholder="0"
/>

<input
  name="per_hour_x"
  id="per_hour_x"
  class="form-control"
  onblur="perhour()"
  value=""
  placeholder="0.00"
/>

Total

<input
  name="per_hour_total"
  id="per_hour_total"
  class="form-control"
  value=""
  placeholder="0.00"
/>

G-Total

<input
  type="text"
  class="form-control total-fare"
  id="total"
  disabled
  value="<?= $booking->total_fare ?>"
/>

<script>
  function perhour() {
    var per_hour = document.getElementById("per_hour").value;
    var per_hour_x = document.getElementById("per_hour_x").value;
    var amts = document.getElementById("total").value;
    var totaperhour = Number(per_hour) * Number(per_hour_x);
    var totalamt = Number(totaperhour) + Number(amts);

    $("#per_hour_total").val(totaperhour).toFixed(2); //working
    $("#total").val(totalamt).toFixed(2); //not working
  }
</script>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It should be $('#per_hour_total').val(totaperhour.toFixed(2)); and not $('#per_hour_total').val(totaperhour).toFixed(2);

function perhour() {
  var per_hour = document.getElementById("per_hour").value;
  var per_hour_x = document.getElementById("per_hour_x").value;
  var amts = document.getElementById("total").value;
  var totaperhour = Number(per_hour) * Number(per_hour_x);
  var totalamt = Number(totaperhour) + Number(amts);

  $('#per_hour_total').val(totaperhour.toFixed(2));
  $('#total').val(totalamt.toFixed(2)); 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div>
  total
  <input type="text" class="form-control total-fare" disabled id="total" value="">
</div>
<div>
  per_hour
  <input name="per_hour" id="per_hour" class="form-control" value="" onblur="perhour()" placeholder="0">
</div>
<div>
  per_hour_x
  <input name="per_hour_x" id="per_hour_x" class="form-control" onblur="perhour()" value="" placeholder="0.00">
</div>
<div>
  per_hour_total
  <input name="per_hour_total" id="per_hour_total" class="form-control" value="" placeholder="0.00">
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda