I'm showing some value in itloop.i. I want to count those values and add it to the text box. This is my code
& lt; Php $ itemCount = count ($ _ POST ["opt"]); For {$ op_name = $ _ POST ['op'] [$ i]; ($ I = 0; $ i & lt; $ itemCount; $ i ++); $ Price = $ _ post ['value'] [$ i]; ? & Gt; & Lt; TR & gt; & Lt; Td> & Lt; Input type = "text" value = "& lt ;? php echo $ op_name ;? & gt;" Name = "opt" /> & Lt; / Td> & Lt; Td> & Lt; Input type = "article" value = "& lt ;? php echo $ price ;? & gt;" Name = "value" id = "value" style = "width: 40px;" Onkeyup = "command ()" /> & Lt; / TD & gt; & Lt; Td> & Lt; Input type = "text" name = "AMT" style = "width: 40px;" Id = "zodiac" onkeyup = "command ()" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt ;? Php}? & Gt; Total & lt; Input type = "text" value = "& lt ;? php echo $ tot;? & Gt;" Id = "tot" /> gt; Onkeyup = "command ()" />
javascript
function order () {var price = document.getElementById ("price"). Value; Var amt = document.getElementById ("zodiac"). value; Var cal_price = 1 * value; Var cal_amt = 1 * AMT; Document.getElementById ("tot"). Value = ((cal_price) * (cal_amt)); }
My code only counts the first row values. I want to have the total amount to be displayed in all the prices * text box
[]
For example, name = "price []"
document.getElementsByName ("value []")
to get the collection of cost areas Use it
function order () {var prices = document.getElementsByName (" value [] "); var amts = document.getElementsByName ( "Var = i; l; value; height; i ++); var cal_price = 1 * pricing [i] value; // or parceflot (" amt [] "); var for total = 0; Value [i] value) var cal_amt = 1 * amts [i] .value; // or parseInt (amts [i] .value, 10) total + = cal_price * cal_amt; } Document.getElementById ("tot"). Value = total.toFixed (2); }
& lt; Table & gt; & Lt; TR & gt; & Lt; Td> & Lt; Input type = "text" value = "" name = "opt []" /> & Lt; / Td> & Lt; Td> & Lt; Input type = "text" value = "1.5" name = "value []" style = "width: 40px;" Onkeyup = "command ()" /> gt; & Lt; / Td> & Lt; Td> & Lt; Input type = "article" name = "AMT []" style = "width: 40px;" Onkeyup = "command ()" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> & Lt; Input type = "text" value = "" name = "opt []" /> & Lt; / Td> & Lt; Td> & Lt; Input type = "text" value = "2.5" name = "value []" style = "width: 40px;" Onkeyup = "command ()" /> gt; & Lt; / Td> & Lt; Td> & Lt; Input type = "article" name = "AMT []" style = "width: 40px;" Onkeyup = "command ()" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> & Lt; Input type = "text" value = "" name = "opt []" /> & Lt; / Td> & Lt; Td> & Lt; Input type = "text" value = "3.25" name = "value []" style = "width: 40px;" Onkeyup = "command ()" /> gt; & Lt; / Td> & Lt; Td> & Lt; Input type = "article" name = "AMT []" style = "width: 40px;" Onkeyup = "command ()" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; & Lt; Input type = "text" id = "tot" />
No comments:
Post a Comment