Calculate the sum of 02 fields automatically

0

I have the following fields:

TheNumberofStudentscomesfromthedatabaseandIamstoringitinahiddenfield:

<inputtype="hidden" name="NumAlunos" id="numAlunos" value="<?php echo $visualizar->NumAlunos; ?>" class="form-control">

How would I multiply this field with the unit value and fill in the Revenue field?

<div class="form-group">
                <label for="valorDesconto">Valor Unitário:</label>
                <div class="input-group">
                  <div class="input-group-addon" style="background-color: #FAFAFA">
                    <i class="fa fa-usd"></i>
                  </div>
                    <input type="text" name="ValorUnitario" class="form-control pull-right" id="valor" maxlength="10">
                </div>
              </div>
              <div class="form-group">
                <label for="valorDesconto">Receita:</label>
                <div class="input-group">
                  <div class="input-group-addon" style="background-color: #FAFAFA">
                    <i class="fa fa-usd"></i>
                  </div>
                    <input type="text" name="ValorReceita" class="form-control pull-right" id="valorReceita" maxlength="10">
                </div>
              </div>
    
asked by anonymous 01.07.2017 / 15:16

1 answer

1

Using Jquery:

Use the Blur function, this function is activated when you exit the selected input ..

$("#valor").blur(function(){
  var receita = $("#numAlunos").val() * $(this).val(); 
  $("#valorReceita").val(receita);
});

This should work

    
01.07.2017 / 17:43