praticamente sono riuscito a trovare questo script, però fa solo operazioni tra interi, ma se volessi farlo con i decimali, con la virgola per capirci?
Sapete dirmi per favore come fare?codice:<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script src="http://www.pengoworks.com/workshop/jquery/field/jquery.field.js"></script> <script src="http://www.pengoworks.com/workshop/jquery/calculation/jquery.calculation.js"></script> <form name="form1" method="post" action=""> <div id="formContent"> <table width="500"> <COL style="width: 50px;"> <COL> <COL style="width: 60px;"> <COL style="width: 110px;"> <tbody> <tr> <th width="179">Qty</th> <th width="164" align="left">Product</th> <th width="72">Pri ce</th> <th width="65">Total</th> </tr> <tr> <td align="center"> <INPUT name="qty_item_1" type="text" class="input" id="qty_item_1" value="1" size="5"> </td> <td>Table</td> <td align="center" id="price_item_1">$150</td> <td align="center" id="total_item_1">$</td> </tr> <tr> <td align="center"> <INPUT name="qty_item_2" type="text" class="input" id="qty_item_2" size="5"> </td> <td>Pencil</td> <td align="center" id="price_item_2">$100</td> <td align="center" id="total_item_2">$</td> </tr> <tr> <td align="center"> <INPUT name="qty_item_3" type="checkbox" id="qty_item_3" value="1,3"> </td> <td>Toys</td> <td align="center" id="price_item_3">$25</td> <td align="center" id="total_item_3">$</td> </tr> <tr> <td align="center"> <select name="qty_item_4" id="qty_item_4"> <option selected="selected">Select an option</option> <option value="1">Book1</option> <option value="1">Book2</option> <option value="1">Book3</option> </select> </td> <td>Books</td> <td align="center" id="price_item_4">$10</td> <td align="center" id="total_item_4">$</td> </tr> <tr> <td colspan="3" align="right">Grand Total:</td> <td align="center" id="grandTotal">$</td> </tr> </tbody> </table> </div> </form> <script>$(document).ready(function() { $("#idPluginVersion").text($.Calculation.version); $("[name^=qty_item_]").bind("change keyup", recalc); recalc(); }); function recalc() { $("[id^=total_item]").calc( "qty * price", { qty: $("[name^=qty_item_]"), price: $("[id^=price_item_]") }, function (s) { return "$" + s.toFixed(2); }, function ($this) { var sum = $this.sum(); $("#grandTotal").text("$" + sum.toFixed(2)); } ); }</script>
grazie ancora

Rispondi quotando