I think your issue is with these lines:
var totship = ($("#totship").val() * 1);
var tottax = ($("#tottax").val() * 1);
The .val()
method in jQuery has a tendency to return Strings. But if you multiply a String by a Number, you get NaN
. You should force the values to be numbers. This seems to be what you're trying to do with * 1
, but that's not going to work. Give this a try instead:
var totship = +$("#totship").val();
var tottax = +$("#tottax").val();
Or if clarity is your thing, you can do:
var totship = Number($("#totship").val());
var tottax = Number($("#tottax").val());
Or
var totship = parseInt($("#totship").val(), 10);
var tottax = parseInt($("#tottax").val(), 10);
Take your pick.