Alechko Posted July 27, 2012 Share Posted July 27, 2012 Hello guys, I have 2 functions that I wrote in JS: function changePrice(divId, sId, price) { document.getElementById(divId).innerHTML = price * document.getElementById(sId).value + ' ₪'; } function changeTotal(id1,id2) { var a = document.getElementById(id1).value; var b = document.getElementById(id2).value; document.getElementById('totalSum').innerHTML = Number(a); } This is the HTML Code: <div class="protitle"> Sum </div> <div class="protitle"> Price </div> <div class="protitle"> Quanity </div> <div class="product-title"> <img src="colors/G.gif" alt=" /> <a href="#" title="#" style="font-size:15px;text-decoration:underline;"> <span style="font-weight:bold;"> Printer </span> HP 51626A </a> </div> <div class="product-sum" id="sum-1"> 1027 ₪</div> <div class="product-price"> 678 ₪</div> <div class="product-quanity"> <form> <select id="selectQuan-1" onChange="changePrice('sum-1','selectQuan-1','678');changeTotal('sum-1','sum-2');"> <option value="1" checked>1</option> <option value="2" checked>2</option> <option value="3" checked>3</option> <option value="4" checked>4</option> <option value="5" checked>5</option> </select> </form> </div> <div class="product-title"> <img src="colors/R.gif" alt=" /> <a href="#" title="#" style="font-size:15px;text-decoration:underline;"> <span style="font-weight:bold;"> Printer </span> HP 51626A </a> </div> <div class="product-sum" id="sum-2"> 1027 ₪</div> <div class="product-price"> 678 ₪</div> <div class="product-quanity"> <form> <select id="selectQuan-2" onChange="changePrice('sum-2','selectQuan-2','678');changeTotal('sum-1','sum-2');"> <option value="1" checked>1</option> <option value="2" checked>2</option> <option value="3" checked>3</option> <option value="4" checked>4</option> <option value="5" checked>5</option> </select> </form> </div> <div class="totalSum" id="totalSum"> </div> I am trying to update automatically the sum in the page. the first function the summing up only the product - working fine. but when I'm trying to TotalSum it gives me an error with 'NaN'. I tried to use the parseInt() function and the Number().. but still the 'NaN' pops to me. help someone? Appriciate it. thanks. Link to comment https://forums.phpfreaks.com/topic/266331-problems-with-nan/ Share on other sites More sharing options...
.josh Posted July 27, 2012 Share Posted July 27, 2012 sum-1 and sum-2 are divs, they don't have value attributes. Link to comment https://forums.phpfreaks.com/topic/266331-problems-with-nan/#findComment-1364927 Share on other sites More sharing options...
scootstah Posted July 28, 2012 Share Posted July 28, 2012 You need to be using .innerHTML, not .value Link to comment https://forums.phpfreaks.com/topic/266331-problems-with-nan/#findComment-1365005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.