I have found a script and I wonder if I have all the numbers of a total code in I have tried the / code> but for some reasons it is not working. By the way, I am not a jquery man, so can you recommend me a solution. Here is a script: HTML Regards, change to and to & lt;
& lt; Input type = "text" id = "sum" / & gt;
$ (document) .ready (function () {// Repeat each text box through each function ($ {$ $} (This) .keyup (function ()} {calculateSum ();}}}})}}; function calculation () {var sum = 0; // Repeat through each text box and values $ (".txt ") Add each (function () {// only if the value is the number (if! (The.value)) and amp; this.value length! = 0) {sum + = parseFloat ( This.value);}}}; // toFixed () method The last amount is 2 decimal places $ ("# Sum"). The goal amount for HTML (sum.toFixed (2));}
< Code> & lt; table width = "300px" border = "1" style = "border-fall: collapse; background color: # E8DCFF"> gt; & lt; tr & gt; & lt; td width = "40px "& Gt; 1 & lt; / td> & lt; td & gt; Butter & lt; / td> gt; & lt; td & gt; & lt; input class =" txt "type =" text " Name = "cost" /> gt; & lt; / tr & gt; & lt; tr & gt; & Lt; TD & gt; 2 & lt; / TD & gt; & Lt; TD & gt; Cheese & lt; / TD & gt; & Lt; Td> & Lt; Input class = "txt" type = "text" name = "cost" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; 3 & lt; / TD & gt; & Lt; TD & gt; Eggs & lt; / TD & gt; & Lt; Td> & Lt; Input class = "txt" type = "text" name = "cost" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; 4 & lt; / TD & gt; & Lt; TD & gt; Milk & lt; / TD & gt; & Lt; Td> & Lt; Input class = "txt" type = "text" name = "cost" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; 5 & lt; / TD & gt; & Lt; TD & gt; Bread & lt; / TD & gt; & Lt; Td> & Lt; Input class = "txt" type = "text" name = "cost" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; 6 & lt; / TD & gt; & Lt; TD & gt; Soap & lt; / TD & gt; & Lt; Td> & Lt; Input class = "txt" type = "text" name = "cost" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; Tr id = "equation" & gt; & Lt; TD & gt; & Nbsp; & Lt; / TD & gt; & Lt; Td align = "right" & gt; Yoga: & lt; / Td> & Lt; Td align = "center" & gt; & Lt; Span id = "sum" & gt; 0 & lt; / Span & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt;
& lt; Span id = "sum" & gt; 0 & lt; / Span & gt;
& lt; Input id = "yoga" value = "0" />
$ ("# sum"). Html (sum.toFixed (2));
$ ("# sum"). Val (sum.toFixed (2));
No comments:
Post a Comment