Friday 15 February 2013

jquery - calculate row wise total and grand total -


for invoicing application, I want to get total and grand total according to the line, these rows are nested. . This is working for the first line when I change the value of the discount, but I want it for all rows.

This is my code.

  $ (".hr" original (); total = 0; qnt = 0; rate = 0; discount = 0; $ (line) .find ("td input.hr") ("Change", function {if ($ (this) .val ()! == "") {if ($ (this) .hasClass ('quantity')) {qnt = ParseFloat ($ (this) .val ());} If ($ (this) .hasClass ('rate')) {rate = parseFloat ($ (this) .val ());} if ($ (this) .hasClass ('discount') ) {Discount = parseFloat ($ (this) .val ());} total return = (qnt * rate) - (discount)}}); $ (line) .find ("td input .total"). Val ( Total); $ ('# invoice_grand_total'). Val (total)}); & Lt; TR & gt; & Lt; Td> & Lt;% = f.text_field: item_name% & gt; & Lt; / Td> & Lt; Td> & Lt;% = f.text_field: Details% & gt; & Lt; / Td> & Lt; Td> & Lt;% = f.text_field: Quantity, Category = & gt; 'Quantity HR'% & gt; & Lt; / Td> & Lt; Td> & Lt;% = f.text_field: rate ,: class = & gt; 'Hour Hour'% & gt; & Lt; / Td> & Lt; Td> & Lt;% = f.text_field: Discounts ,: class = & gt; 'Discount Hour'% & gt; & Lt; / Td> & Lt; TD & gt; & Lt; Td> & Lt;% = f.text_field: aggregate, class = & gt; 'Total',: disabled = & gt; True% & gt; & Lt; / Td> & Lt; / TR & gt;    

I do not know when you do this $ ("every" / Code> code, but it will not update equals and #invoice_grand_total when your .hr element changes since Val (total) statements for those areas are outside of the function . on function, set the value to it.

No comments:

Post a Comment