0
Good evening, I am with a Radiogroup that return me three values: PM - Lower Weight (The lowest weight between Outgoing Weight and Finish Weight); PS - Output Weight; PC - Arrival Weight;
The system must take the value of the field Pptdriver and then perform the calculation by multiplying by the parameter selected above and dividing the result by a thousand for ai yes display in the Driver Freight field.
<div class="row">
<div class="small-2 large-4 columns">
<label>PPT Motorista</label>
<input type="number" placeholder="170,00" name="PptMotorista" id="PptMotorista"/>
</div>
<div class="small-2 large-4 columns end">
<label>Frete Motorista</label>
<input type="number" name="FreteMotorista" id="FreteMotorista" readonly="readonly" tabindex="-1"/>
</div>
</div>
<div class="row">
<fieldset class="large-6 medium-6 columns">
<legend>Cálculo do Frete</legend>
<input type="radio" name="calculoFrete" value="PM" id="menorpeso" required checked><label for="menorPeso">Menor Peso</label>
<input type="radio" name="calculoFrete" value="PS" id="pesosaida"><label for="pesoSaida">Peso de Saída</label>
<input type="radio" name="calculoFrete" value="PC" id="pesochegada"><label for="pesoChegada">Peso de Chegada</label>
</fieldset>
</div>
<script type="text/javascript">
var bPptMotorista = document.getElementById( 'PptMotorista' );
var bFreteMotorista = document.getElementById( 'FreteMotorista' );
var bTipoPeso;
var bRadioGroupPeso = '';
$(document).ready(function(){
$("*[name='calculoFrete']").change(function(){
bRadioGroupPeso = ($(this).attr('value'));
});
});;
if (bRadioGroupPeso == 'PS'){
bTipoPeso = document.getElementById('PesoSaida');
} else if (bRadioGroupPeso == 'PC') {
bTipoPeso = document.getElementById('PesoChegada');
} else {
bTipoPeso = document.getElementById('PesoChegada') - document.getElementById( 'PesoTotal' );
}
bPptMotorista.onkeyup=calcula_frete;
bTipoPeso.change=calcula_frete;
function calcula_frete() {
bFreteMotorista.value = ((bTipoPeso.value / 1000) * bPptMotorista.value);
}
</script>
</body>
But the code I wrote, I don’t know why you’re not taking the values, performing the calculation and playing in the Text of Freight Driver. Someone can help me and check if the code has something incorrect. Thank you.
The variables
aPesoChegda
andaPesoTotal
they are in another function, is that valid? It is just above the one I described in the question.– Juliano Bazzi
If you declared these variables within a function, they are only accessible within that function. To use the same variable in two places, you can declare for example at the beginning of the script, in general scope, outside any function.
– user28527
For a Radiogroup which is the best event I should use, I think the
bTipoPeso.onkeyup=calcula_frete
will not work properly.– Juliano Bazzi
As you are using jQuery, you can use the event
change
(https://api.jquery.com/change/).– user28527
made some changes to the code, but my knowledge of java script and jquery is very vague.
– Juliano Bazzi