I want to display the sum of this calculation in an input field:
function calculateSum1() {
var sum = 0;
//iterate through each textboxes and add the values
$("input.miles").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum += parseFloat(this.value);
}
});
$("input.summiles").value(sum);
}
input field:
<input class="summiles" type="text" value="">
It works fine if I display it in a span, but I can’t seem to get it to display in an input field. Any ideas? Thanks!
You need to use val() instead of
value()to set the textbox.