coupe-r Posted January 13, 2011 Share Posted January 13, 2011 Here is my function. Everything works great, but my total_txt field never has decimals. function Fn_Add() { var first ="0" var second="0" var third="0" if(document.getElementById ("subtotal_txt").value!="") { first =document.getElementById ("subtotal_txt").value } else { document.getElementById("subtotal_txt").value="0" } if(document.getElementById ("tax_txt").value!="") { second=document.getElementById ("tax_txt").value } else { document.getElementById("tax_txt").value="0" } document.getElementById ("total_txt").value=parseInt(first)+parseInt(second) + parseInt(third) } Link to comment https://forums.phpfreaks.com/topic/224280-need-my-addition-function-to-have-decimals/ Share on other sites More sharing options...
coupe-r Posted January 13, 2011 Author Share Posted January 13, 2011 GOT IT!!! function Fn_Add() { var first ="0" var second="0" var total="" if(document.getElementById ("subtotal_txt").value!="") {first =document.getElementById ("subtotal_txt").value} else {document.getElementById("subtotal_txt").value="0"} if(document.getElementById ("tax_txt").value!="") {second=document.getElementById ("tax_txt").value} else {document.getElementById("tax_txt").value="0"} total = parseFloat(first)+parseFloat(second) document.getElementById ("total_txt").value=total.toFixed(2) } Link to comment https://forums.phpfreaks.com/topic/224280-need-my-addition-function-to-have-decimals/#findComment-1158786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.