Zero Specific field in the Form

0

As I do not have much knowledge in javascript I ask for help from you ... In this code, I need to reset a specific field that is the People field by the last field Select

This form is a calculator, you would like it if you clicked on the last field it retains itself only the field People automatically correcting the summation

I need a simple solution without completely changing this code

$(document).ready(function() {
  $(".valores1").change(function() {
    var total = 1000;
    total += $('input[class="valores1"]:checked').get().reduce(function(tot, el) {
      return tot + Number(el.value);
    }, 0);
        
        
    var e = document.getElementById("valores2");
    var itemSelecionado = e.options[e.selectedIndex].value;
    
    var primeiroDigito = (itemSelecionado.substring(0,1));
    total=total+(primeiroDigito*100);
    
    
    
    var d = document.getElementById("valores3");
    var itemSelecionado3 = d.options[d.selectedIndex].value;
    
    var primeiroDigito3 = (itemSelecionado3.substring(0,1));
    total=total+(primeiroDigito3*100);
    
    var g = document.getElementById("valores4");
    var itemSelecionado4 = g.options[g.selectedIndex].value;
    
        
    var primeiroDigito4 = (itemSelecionado4.substring(0,1));
    total=total+(primeiroDigito4/100);
    
    
    
    
    
    
    //aqui pega primeiro digito
    
    $('#total1').val(total.toFixed(2));     
  });  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>Duplica:<inputtype="checkbox" class="valores1" onclick="Mudarestado('minhaDiv')" name="direcao" value="1000" id="option_1"  />
Adciona:<input type="checkbox" class="valores1" name="bilingue" value="200" id="option_1"  />

<select id="valores2"   class="valores1 form-control" name="cadeirinha" >
    <option value="0">Passageiros</option>
    <option value="1">x1</option>
    <option value="2">x2</option>
    <option value="3">x3</option>
    
</select>  

<select id="valores3"   class="valores1 form-control" name="cadeirinha2" >
    <option value="0">Pessoas</option>
    <option value="1">x1</option>
    <option value="2">x2</option>
    <option value="3">x3</option>
    
</select>  

<select id="valores4"   class="valores1 form-control" name="cadeirinha2" >
    
    <option value="0"></option>
    <option value="0">zerar</option>
    <option value="2">x2</option>
   
    
</select>  


<input type="text" size="5"  readonly="" name="valor" id="total1" value="1000.00" style="background-color: transparent; border-color: transparent; font-weight: bold; font-size: 18px; color: green; "    />
    
asked by anonymous 28.12.2017 / 15:52

1 answer

1

First of all, there is only a small problem with <option value="0">zerar</option> , which has the same value of default . Pro code that I added below, I took into account that option was changed to 1.

If the option zero is selected, I reset the people field and decrease the total from the value of the people field.

if (g.value == 1) {
  d.value = 0;
  g.value = 0;
  total = total-(primeiroDigito3*100);
  $('#total1').val(total);
}
    
28.12.2017 / 16:29