[英]two text box values sum into another text box in a table using javascript?
i tried a code for summing values of two text boxes and store it into another text box. 我尝试了将两个文本框的值求和并将其存储到另一个文本框中的代码。 The summing is working properly. 汇总工作正常。 but i didn't getting the result into a text box.please help me with the code snippet.. 但我没有将结果输入文本框。请帮助我提供代码段。
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script>
$(document).ready(function(){
$('#tablesum').find('input:text').each(function() {$(this).keyup(function(){
newSum.call(this);
});
});
});
function newSum() {
var sum=0;
var thisRow = $(this).closest('tr');
var total=0;
//iterate through each input and add to sum
$(thisRow).find("td:not(.total) input").each(function() {
console.log($(this).attr('id') );
sum += parseInt(this.value);
});
//change value of total
$(thisRow).find(".total").html(sum);
// the grand total
$('.total').each(function() {
total += parseInt($(this).html());
});
$('.result').val(total);
}
</script>
//html // html
<tr>
<td> i) Full Time employees</td>
<td class="tdright total" ><input type=text id="2.1_1_1" name="2.1_1_1" title="qry"></td>
<td><input type=text id="2.1_1_2" name="2.1_1_2" title="qry"></td>
<td><input type=text id="2.1_1_3" name="2.1_1_3" title="qry"></td>
</tr>
saving two text box values and outputting the result in anothor,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.