Calculate the grand total with javascript (onkeyup) -
Calculate the grand total with javascript (onkeyup) -
how calculate grand total total using java script (onkeyup)? coding
<html> <head> <form method = "post" action="text.php" name="form"> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="css/jquery-ui.css"/> <script src="js/jquery-1.9.1.js"></script> <script src="js/jquery-ui.js"></script> <!--<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>--> <script type="text/javascript"> function cal1() { var = $(".qty1").val(); var b = $(".price1").val(); c1 = * b; //a * b $(".total1").val(c1); } function cal2() { var = $(".qty2").val(); var b = $(".price2").val(); c2 = * b; //a * b $(".total2").val(c2); } function grandtotal() { var = $(".total1").val(); var b = $(".total2").val(); z = a+b; //+ $(".grandtotal").val(z); } </script> </head> <body> <table border="1"> <tr> <td> <table height="51" border="0" cellspacing="2"> <tr> <td> <div align="center">price</div> </td> <td> <div align="center"> total price</div> </td> </tr> <tr> <td> <input class="qty1" type="text" name="qty1" onblur="qty_blur(this);" onkeyup="cal1();" value=""> </td> <td> <input class="price1" type="text" name="price1" onblur="price_blur(this);" onkeyup="cal1();" value=""> </td> <td> <input class="total1" type="text" name="total1" value="0" readonly=true onkeyup="grandtotal();"> </td> </tr> <tr> <td> <input class="qty2" type="text" name="qty2" onblur="qty_blur(this);" onkeyup="cal2();" value=""> </td> <td> <input class="price2" type="text" name="price2" onblur="price_blur(this);" onkeyup="cal2();" value=""> </td> <td> <input class="total2" type="text" name="total2" value="0" readonly=true onkeyup="grandtotal();"> </td> </tr> </table> </td> </tr> </table> <table> <tr div class="grandtotal"> <td> grand total : </td> <td> <input class="grandtotal" name="grandtotal" type="text" readonly=true value=""> </td> </tr> </div> </table> </body> </html>
it's right cal1 , cal2, grand total maintain empty when cal , cal2 calculate?? how grand total auto calculate +??? form total cal1 , total cal2
you have associated grandtotal
onkeyup
totals inputs. inputs never receive onkeyup
because readonly
.
as quick solution suggest calling grandtotal
cal1
, cal2
:
function cal1() { var = $(".qty1").val(); var b = $(".price1").val(); c1 = * b; //a * b $(".total1").val(c1); grandtotal(); } function cal2() { var = $(".qty2").val(); var b = $(".price2").val(); c2 = * b; //a * b $(".total2").val(c2); grandtotal(); }
also, @myfunkyside suggest, have parse inputs numbers. otherwise you'll totals concatenated strings.
function grandtotal() { var = parseint($(".total1").val(), 10); var b = parseint($(".total2").val(), 10); z = a+b; //+ $(".grandtotal").val(z); }
javascript
Comments
Post a Comment