Variável dinâmica
Tenho o seguinte script que é uma lista de pedidos que realiza o calculo estantaneo multiplicando a quantidade
do produto pelo valor e no final realiza um somatório de todos os pedidos.
Segue o script que realiza isso, mas ele funciona somente para 10 ítens, alguem sabe como faço
para que eu aumente dinamicamente estes itens sem ter que repetir. Ou seja com apenas um ítem
fazer com que as variáveis seja criadas dinamicamente como se fosse um for.
Tentei colocar em um laço (FOR) mas não tive sucesso.
Segue o script que tenho:
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
/*MASCARA 0 */
one0 = document.autoSumForm.qtd0.value;
two0 = document.autoSumForm.pre0.value;
two0 = two0.replace(".", "");
two0 = two0.replace(",", "");
sub0=((one0 * 1) * (two0 * 1)/100);
resul0=document.autoSumForm.subTot0.value = sub0.toFixed(2);
/*MASCARA 1 */
one1 = document.autoSumForm.qtd1.value;
two1 = document.autoSumForm.pre1.value;
two1 = two1.replace(".", "");
two1 = two1.replace(",", "");
sub1=((one1 * 1) * (two1 * 1)/100);
resul1=document.autoSumForm.subTot1.value = sub1.toFixed(2);
/*MASCARA 2 */
one2 = document.autoSumForm.qtd2.value;
two2 = document.autoSumForm.pre2.value;
two2 = two2.replace(".", "");
two2 = two2.replace(",", "");
sub2=((one2 * 1) * (two2 * 1)/100);
resul2=document.autoSumForm.subTot2.value = sub2.toFixed(2);
/*MASCARA 3 */
one3 = document.autoSumForm.qtd3.value;
two3 = document.autoSumForm.pre3.value;
two3 = two3.replace(".", "");
two3 = two3.replace(",", "");
sub3=((one3 * 1) * (two3 * 1)/100);
resul3=document.autoSumForm.subTot3.value = sub3.toFixed(2);
/*MASCARA 4 */
one4 = document.autoSumForm.qtd4.value;
two4 = document.autoSumForm.pre4.value;
two4 = two4.replace(".", "");
two4 = two4.replace(",", "");
sub4=((one4 * 1) * (two4 * 1)/100);
resul4=document.autoSumForm.subTot4.value = sub4.toFixed(2);
/*MASCARA 5 */
one5 = document.autoSumForm.qtd5.value;
two5 = document.autoSumForm.pre5.value;
two5 = two5.replace(".", "");
two5 = two5.replace(",", "");
sub5=((one5 * 1) * (two5 * 1)/100);
resul5=document.autoSumForm.subTot5.value = sub5.toFixed(2);
/*MASCARA 6 */
one6 = document.autoSumForm.qtd6.value;
two6 = document.autoSumForm.pre6.value;
two6 = two6.replace(".", "");
two6 = two6.replace(",", "");
sub6=((one6 * 1) * (two6 * 1)/100);
resul6=document.autoSumForm.subTot6.value = sub6.toFixed(2);
/*MASCARA 7 */
one7 = document.autoSumForm.qtd7.value;
two7 = document.autoSumForm.pre7.value;
two7 = two7.replace(".", "");
two7 = two7.replace(",", "");
sub7=((one7 * 1) * (two7 * 1)/100);
resul7=document.autoSumForm.subTot7.value = sub7.toFixed(2);
/*MASCARA 8 */
one8 = document.autoSumForm.qtd8.value;
two8 = document.autoSumForm.pre8.value;
two8 = two8.replace(".", "");
two8 = two8.replace(",", "");
sub8=((one8 * 1) * (two8 * 1)/100);
resul8=document.autoSumForm.subTot8.value = sub8.toFixed(2);
/*MASCARA 9 */
one9 = document.autoSumForm.qtd9.value;
two9 = document.autoSumForm.pre9.value;
two9 = two9.replace(".", "");
two9 = two9.replace(",", "");
sub9=((one9 * 1) * (two9 * 1)/100);
resul9=document.autoSumForm.subTot9.value = sub9.toFixed(2);
tot = (resul0 * 1) + (resul1 * 1) + (resul2 * 1) + (resul3 * 1) + (resul4 * 1) + (resul5 * 1) + (resul6 * 1) + (resul7 * 1) + (resul8 * 1) + (resul9 * 1);
resultotal=document.autoSumForm.thirdTot.value = tot.toFixed(2);
}Discussão (6)
Carregando comentários...