javascript - How to show the total value of multiple text field? -
javascript - How to show the total value of multiple text field? -
how can show total value of id="total" in id="grand". whole code. html , javascript should used. don't know how add together value of each. javascript exeuted when user checked checkbox. value of checkbox multiplied value of dropdown value. product displayed in input id="total". want sum value in input id=total , display in input id="grand"
<p><center><font size="5">total amount: <input type="text" id="grand" name="grand" value="p0.00"></input></p> <table border=1> <tr> <td colspan=3><h2>specialty cakes</h2></td> </tr> <tr> <td><center><img src=special\blackforest_small.jpg ><br>black forest</td> <td><input type="checkbox" id="check1" name="check1" value="550.00"onclick="special1()">buy p550.00</input><br><input type="text" id="total1" name="total1" value="p0.00"size="8"></input><br> qty: <select id="qty1" name="qty1" onchange="special1()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> </select> </td> </tr> <tr> <td><center><img src=special\chocolata_small.jpg><br>chocolata</center></td> <td><input type="checkbox" id="check2" name="check2" value="550.00"onclick="special2()">buy p500.00</input><br><input type="text" id="total2" name="total2" value="p0.00"size="8"></input><br> qty: <select id="qty2" name="qty2" onchange="special2()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> </select> </td> </tr> </table> <script> function special1(){ var m = document.getelementbyid("check1").checked; var x = document.getelementbyid("check1").value; var y = document.getelementbyid("qty1").value; var z = 0; if (m == true){ z = "p" + x * y; } document.getelementbyid("total1").value = z; } function special2(){ var m = document.getelementbyid("check2").checked; var x = document.getelementbyid("check2").value; var y = document.getelementbyid("qty2").value; var z = 0; if (m == true){ z = "p" + x * y; } document.getelementbyid("total2").value = z; } </script>
in js + works left right. adding string enything else produce string, need watch order of operations.
z = "p" + (x * y);
javascript html
Comments
Post a Comment