3
As I don’t have much knowledge of javascript I need a little help from you.
This my script is a simple calculator but I’m not able to make some functions work. I just need that
- When choosing a Radio Field it shows the field value
- And then immediately multiply the dropdwon n bags x value of the chosen radio field and add to the final calculation
Below follows the script working if possible need a solution that moves the least possible code
$(document).ready(function() {
$(".valores1").change(function() {
var total = 50;
total += $('input[class="valores1"]:checked').get().reduce(function(tot, el) {
return tot + Number(el.value);
}, 0);
var f = document.getElementById("valores7");
var itemSelecionadof = f.value;
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*itemSelecionadof);
//////////////////////////////////////////////////////////////
var g = document.getElementById("valores4");
var itemSelecionado4 = g.options[g.selectedIndex].value;
if (g.value == 1) {
d.value = 0;
g.value = 0;
f.value = 0
total = total-(primeiroDigito3*100);
$('#total1').val(total);
}
//////////////////////////////////////////////////////////////
//aqui pega primeiro digito
$('#total1').val(total.toFixed(2));
});
});
<form>
PERA:<input type="checkbox" class="valores1" name="direcao" value="10" id="option_1" />
Banana:<input type="checkbox" class="valores1" name="bilingue" value="15" id="option_1" /><br />
<select id="valores2" class="valores1 form-control" name="tipo carnes" >
<option value="0">Carnes</option>
<option value="1">1 Picanha</option>
<option value="2">2 Picanhas</option>
<option value="3">3 Picanhas</option>
</select> <br /><br />
Sacola Pequena<input type="radio" class="valores1" name="normal" value="100" id="valores7" />
Sacola Grande<input type="radio" class="valores1" name="normal" value="150" id="valores7"/>
====>Mostrar Valor da sacola<input type="text" size="5" readonly="" id="valorsacola" name="valor da sacola" value="0.00" style="background-color: transparent; border-color: transparent; font-weight: bold; font-size: 18px; color: green; " />
<br />
<select id="valores3" class="valores1 form-control" name="nsacolas" >
<option value="0">N de Sacola</option>
<option value="1">x1</option>
<option value="2">x2</option>
<option value="3">x3</option>
</select>
<br /><hr />
Zerar Calculo da Sacola
<select id="valores4" class="valores1 form-control" name="cadeirinha2" >
<option value="0"></option>
<option value="1">zerar</option>
<option value="2">x2</option>
</select>
<br /><br /><br />
Consumação Minima
<input type="text" size="5" readonly="" name="valor" id="total1" value="50.00" style="background-color: transparent; border-color: transparent; font-weight: bold; font-size: 18px; color: green; " />
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
is that this script is only for demonstration after I take the logic and step to my system. I put it as an example
– Fabio Henrique
This initial value of 50 is fixed? Let’s assume that the guy choose bag of 100 x 2, would be the total 250?
– Sam