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

126
Visualizações
onChange Event is returning an empty field

I want to update a id="total_fee" input on changing the values in input fields.

This is my HTML;

<td class="'.$bg_trow.$challan_created_shade.'" align="center">
  <div>
    <div style="font-size: 11px;">Actual Fee</div>
    <input type="text" class="small_input_box" id="actual_fee_'.$f['fid'].'" style="background: #EFEFEF; border: 1px solid #000; color: #000;" name="actual_fee" size="5" value="1400" readonly="readonly">
  </div>
  <div>
    <div style="font-size: 11px;">Monthly Fee</div>
    <input onchange="findTotal_'.$f['fid'].'()" type="text" class="small_input_box fee_'.$f['fid'].'" name="monthly_fee" size="5" value="1000">
  </div>
</td>
<td class="'.$bg_trow.$challan_created_shade.'" align="center">
  <div>
    <div style="font-size: 11px;">Paper Money</div>
    <input onchange="findTotal_'.$f['fid'].'()" type="text" class="small_input_box fee_'.$f['fid'].'" name="paper_money_fee" size="5" value="">
  </div>
  <div>
    <div style="font-size: 11px;">Previous Balance</div>
    <input onchange="findTotal_'.$f['fid'].'()" type="text" class="small_input_box fee_'.$f['fid'].'" name="previous_balance" size="5" value="">
  </div>
</td>
<td class="'.$bg_trow.$challan_created_shade.'" align="center">
  <div>
    <div style="font-size: 11px;">Total Fee</div>
    <input type="text" class="small_input_box" style="background: #EFEFEF; border: 1px solid #000; color: #000;" name="total_fee" id="total_fee_'.$f['fid'].'" size="5" value="" readonly="readonly">
  </div>
</td>

and this is my JavaScript function;

function findTotal_'.$f['fid'].'() {
  const fees = document.querySelectorAll(".fee_'.$f['fid'].'");
  const total = document.querySelector("#total_fee_'.$f['fid'].'");
  let sum = 0;
  fees.forEach((fee) => {
    if (fee.valueAsNumber) {
      sum += fee.valueAsNumber;
    }
  });
  total.value = sum;
}

When the values are changed in input field, it is returning zero. I don't know why. Plz help.

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

0

You can use fee.value instead of using fee.valueAsNumber and also you should use valid identifiers (name) for your functions ie. the name findTotal_'.$f['fid'].' is not a valid one.

about 4 years ago · Juan Pablo Isaza Relatório

0

Okay..

I have done it by meself, by changing the javascript function to this;

function findTotal_'.$f['fid'].'()
        {
            const fees = document.querySelectorAll(".fee_'.$f['fid'].'");
            const total = document.querySelector("#total_fee_'.$f['fid'].'");
            let sum = 0;
            fees.forEach(fee => {
                if(fee.value)
                {
                    sum += + fee.value;
                }   
            });
            total.value = sum;
        }

Thank you everyone.

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