将自动完成的文本字段的值添加到其他文本字段, [英] adding the values of textfield of autocomplete to other textfield,
问题描述
我有一个问题,我有一个名为total的文本字段,该文本字段是自动完成的,由用户动态添加,现在的问题是如何将所有这些total的结果添加到称为小计
这是我的代码,请帮助
Hi ,
I Hav a problem ,I have a textfield called total which is autocomplete which dynamically added by user ,now the question is how to add the result of all these total in the onther field called subtotal
here is my code please help
calculate = function(){
var eles = document.getElementsByName("txttot");
for (var i = 0, i < eles.length; i++)
{
if (document.getElementById('txttot').value != "")
{
document.getElementById('txtsub').value = document.getElementById('txttot').value
}
}
};
这里"txttot"是文本字段总计n的名称"txtsub"是名称os小计,我必须在其中添加所有总计n的值store
here "txttot" is the name of textfield total n "txtsub" is the name os subtotal where I have to add the values of all the totals n store
推荐答案
document.getElementById(''txtsub'').value = document.getElementById(''txttot'').value
每次都会覆盖document.getElementById(''txtsub'')的值
您应该实现这样的内容
The value of document.getElementById(''txtsub'') is overwritten everytime
You should implement something like this
var subTotal;
foreach(element)
{
subTotal += parseInt(element value);
}
您还应该研究并学习使用JQuery.它使使用JavaScript变得非常容易.
You should also investigate and learn to use JQuery. It makes working with JavaScript very easy.
是的,大家好,
我自己解决了这是我的代码
caltot = function(){
var total = 0;
var eles = document.getElementsByName("txttot");
for(var i = 1; i< eles.length; i ++){
if(eles [i] .value!=";){
总计+ = eles [i] .value * 1;
}
}
cal; tot是一个函数,我将其称为ic的另一个函数计算在何处计算文本字段"txttot"的总和.在这里,我将txttot的所有值放入具有iits名称为i,e"txttot"的数组eles中,检查了n然后将eles数组n的长度n值添加到增值税总计中.
Ya Hi every one ,
I solved it myself here is my code
caltot = function () {
var total = 0;
var eles = document.getElementsByName("txttot");
for (var i = 1; i < eles.length; i++) {
if (eles[i].value != "";) {
total += eles[i].value * 1;
}
}
cal;tot is a function which i call ic another funtion Calculate where I calculate the total of textfield "txttot".here I hav Put all the values of txttot in an array eles with iits name i,e "txttot" , n hav checked the length n value of eles array n then added that to vat total.
这篇关于将自动完成的文本字段的值添加到其他文本字段,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!