0

Hi, i would like to ask something, i have a table like this : c60f5fee223b1398d53631dda019f205

The user will enter a value in the column "out Quantity", then, i want it auto calculate in "Total Price" which is
Total Price = Old balance quantity * out quantity and
new Balance = old balance quantity - out Quantity

how can i do that?

I tried to do it like this, but it won't work :

<script>
function compute() {
    var price = document.getElementById('valuePerUnit');
    var outqty = document.getElementById('k9goodsQty');
    var total = document.getElementById('valueTotal');
    var oldqty = document.getElementById('goodsQty');
    var balance = document.getElementById('qtyBalance');

    var v1=value.value;
    var v2=outqty.value;
    var v3=total.value;
    var v4=oldqty.value;
    var v5=balance.value

    var val1 = v1==="" ? 0 : parseFloat(v1); 
    var val2 = v2==="" ? 0 : parseFloat(v2);
    var val3 = v3==="" ? 0 : parseFloat(v3);
    var val4 = v4==="" ? 0 : parseFloat(v4);
    var val5 = v5==="" ? 0 : parseFloat(v5);    

    jumlah.value = val1 * val2;
    baki.value =  val4 - val2;
    }
</script>
4
Contributors
6
Replies
49
Views
4 Years
Discussion Span
Last Post by JorgeM
0

I tried to do it like this, but it won't work :

@sagisgirl

On line 15 to line 20:

var val1 = v1==="" ? 0 : parseFloat(v1);
var val2 = v2==="" ? 0 : parseFloat(v2);
var val3 = v3==="" ? 0 : parseFloat(v3);
var val4 = v4==="" ? 0 : parseFloat(v4);
var val5 = v5==="" ? 0 : parseFloat(v5);

Why you have an extra equal sign?

Plus how does your html code looks like related to your javascript code?

0

actually I found the code on the internet(but it is simpler), so I modified a little bit the code..so, Im not sure why there is an extra equal sign.

    <script>
    function compute() {
    var price = document.getElementById('valuePerUnit');
    var outqty = document.getElementById('k9goodsQty');
    var total = document.getElementById('valueTotal');
    var oldqty = document.getElementById('goodsQty');
    var balance = document.getElementById('qtyBalance');

    var v1=value.value;
    var v2=outqty.value;
    var v3=total.value;
    var v4=oldqty.value;
    var v5=balance.value

    var val1 = v1==="" ? 0 : parseFloat(v1);
    var val2 = v2==="" ? 0 : parseFloat(v2);
    var val3 = v3==="" ? 0 : parseFloat(v3);
    var val4 = v4==="" ? 0 : parseFloat(v4);
    var val5 = v5==="" ? 0 : parseFloat(v5);

    total.value = val1 * val2;
    balance.value = val4 - val2;
    }
    </script>
0

The extra equal sign is there for static-Type comparison, i.e.: to avoid the literal 0 (zero) to evaluate as a Boolean false.

0

@TroyIII
so can you help me,on how to do it..? please guide me..

0

of course if you tell me what does sagis-girl mean.

for a start there's a trasncript redoundant word or brain glitch error during transcription on line
9. var v1=value.value;
it should be correspondently equal to:
9. var v1=price.value; //instead

Edited by Troy III

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.