Add two selected value together, then display results JavaScript -
been trying values id tags totaldiv-totaldiv1 each display results selected values, add them display values combined in real time in id tag totalall keep getting nan.
<h2>£10 each</h2> <select name="iteam1" onchange="calc1()"> <option value="10">1</option> <option value="20">2</option> <option value="30">3</option> <option value="40">4</option> <option value="50">5</option> </select> <div id="totaldiv1">£10</div> <h2>£10 each</h2> <select name="iteam" onchange="calc()"> <option value="10">1</option> <option value="20">2</option> <option value="30">3</option> <option value="40">4</option> <option value="50">5</option> </select> <div id="totaldiv">£10</div> <br> <h2>total</h2> <div id="totalall">£0</div> <script> function calc() { var fruitorveg = document.getelementsbyname("iteam")[0].value; var total = fruitorveg; document.getelementbyid("totaldiv").innerhtml= "£" +(total); } </script> <script> function calc1() { var fruitorveg = document.getelementsbyname("iteam1")[0].value; var total = fruitorveg; document.getelementbyid("totaldiv1").innerhtml= "£" +(total); } </script> <script> window.onload = function total() { var y = document.getelementbyid("totaldiv").value; var z = document.getelementbyid("totaldiv1").value; var x = +y + +z; document.getelementbyid("totalall").innerhtml = "£" + x; } </script>
point take care. 1. don't mix value , symbol 2. adding symbol in calc function in div , later tried combine them both obiviously not number;
<h2>£10 each</h2> <select name="iteam1" onchange="calc1()"> <option value="10">1</option> <option value="20">2</option> <option value="30">3</option> <option value="40">4</option> <option value="50">5</option> </select> <div id="totaldiv1">£ <span id="totaldiv1value">0</span> </div> <h2>£10 each</h2> <select name="iteam" onchange="calc()"> <option value="10">1</option> <option value="20">2</option> <option value="30">3</option> <option value="40">4</option> <option value="50">5</option> </select> <div id="totaldiv">£ <span id="totaldivvalue">0</span> </div> <br> <h2>total</h2> <div id="totalall">£0</div> <script> function calc() { var fruitorveg = document.getelementsbyname("iteam")[0].value; var value = fruitorveg; document.getelementbyid("totaldivvalue").innerhtml= value; total(); } function calc1() { var fruitorveg = document.getelementsbyname("iteam1")[0].value; var value = fruitorveg; document.getelementbyid("totaldiv1value").innerhtml= value; total(); } function total() { var y = parseint(document.getelementbyid("totaldivvalue").innerhtml); var z = parseint(document.getelementbyid("totaldiv1value").innerhtml); var x = y+z; document.getelementbyid("totalall").innerhtml = "£" + x; } </script>
Comments
Post a Comment