javascript - Simple math but its not working? -
this question has answer here:
- how force js math instead of putting 2 strings together 7 answers
- how add 2 strings if numbers? 15 answers
i have table users can enter part number, part price , quantity. multiple's price , quantity total. got part , running.
now have taxes on part , grand total im getting:
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 total of taxes * parts var myresult = mybox1 * mybox2; //result = taxes * parts total result.value = myresult; // display results var result2 = document.getelementbyid('partstotalwithtax'); // inputp field taxes + total value var totalresult = myresult + mybox2; // totalresult = taxes on part + parts total result2.value = totalresult; // display results }
here's fiddle:
problem + operator , variable types.
in case try add string
var = "1" + "2"; <- 12
what need use parsefloat , math
var = parsefloat("2") + parsefloat("2.14") <- 4.14
hope helps.
Comments
Post a Comment