我有一個表格,用戶可以輸入零件號碼,零件價格和數量。然後它的倍數是價格和數量,以獲得總數。我把這部分開始運行起來。簡單的數學,但它不工作?
現在我已經得到了部分稅收,然後總計但是這是即時得到:
function calculateit() {
var myBox1 = $('input[name=tax2]:checked').val(); //taxes value
var myBox2 = document.getElementById('partstotalvalue').value; //parts total value
var result = document.getElementById('partstax'); // input field for the total of taxes * parts
var myResult = myBox1 * myBox2; //result = taxes * parts total
result.value = myResult; // display the results
var result2 = document.getElementById('partstotalwithtax'); // inputp field for taxes + total value
var totalResult = myResult + myBox2; // totalresult = taxes on part + the parts total
result2.value = totalResult; // display the results
}
這裏的小提琴:
https://jsfiddle.net/jdarville/hxqev0be/
看起來你正在嘗試添加字符串而不是數字。 –
僅供參考,當您從DOM中讀取值時,它們被讀作字符串而不是數字。您將不得不使用'parseFloat'或'parseInt'手動將其解析爲數字。另外,'+'運算符也是字符串的concatination運算符 – Rajesh
你能給我一個小提琴嗎? –