1
Guys, I’m developing a form that will calculate the value of the freight and discount the debts to reach the net amount that the Driver has to receive. But I wanted some fields to display the values as the user fills in the form.
For example the image, the "Weight Difference" field will calculate the "Output Weight" - "Arrival Weight" to know the difference. Does anyone know of any Javascript/jQuery tutorial that performs something similar that I can base on?
<script type="text/javascript">
var tPesoSaida = document.getElementById( 'ps' );
var tPesoChegada = document.getElementById( 'pc' );
var tPesoTotal = document.getElementById( 'pt' );
tPesoSaida.onkeyup=calcula;
tPesoChegada.onkeyup=calcula;
function calcula() {
tPesoTotal.value = (tPesoSaida.value - tPesoChegada.value);
}
</script>
<div class="small-2 large-4 columns">
<label>Peso de Saída</label>
<input type="text" value="0" placeholder="37000" name="PesoSaida" id="ps"/>
</div>
<div class="small-2 large-4 columns">
<label>Peso de Chegada</label>
<input type="text" value="0" placeholder="37090" name="PesoChegada" id="pc"/>
</div>
<div class="small-2 large-4 columns">
<label>Diferença de Peso</label>
<input type="text" value="0" name="PesoTotal" id="pt" readonly="readonly" tabindex="-1"/>
</div>
And what have you tried to do so far? What is your specific difficulty?
– gmsantos
I’ve been researching, but I couldn’t find anything related to jQuery that is like a "get out of the field" to perform the event.
– Juliano Bazzi
With this you can calculate while the user is typing... http://stackoverflow.com/questions/1481152/how-to-detect-a-textboxs-content-has-changed
– gmsantos
But how will I tell who is input1, input2 and input3? To pass the values.
– Juliano Bazzi
Id, field name... any valid selector.
– gmsantos
Are you really wrong the way I asked the question now? @gmsantos
– Juliano Bazzi
@Julianobazzi if you put the snippet of the HTML that has the fields, help.
– Bacco
@Bacco edited the question with the source code of the form. Thank you.
– Juliano Bazzi