Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

arldin

[Resolvido] Calculo

Recommended Posts

Bom dia amigos eu estou querendo que este script some os campos que são o "sub tota" com o "total do frete" sendo retornado em "total com o frete"

Este e o script

<script LANGUAGE="JavaScript">  
addEvent = function(o, e, f, s) { 
   var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d; 
   r[r.length] = [f, s || o], o[e] = function(e){ 
      try{ 
         (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;}); 
         e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;}); 
         e.target || (e.target = e.srcElement || null); 
         e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0; 
      }catch(f){} 
      for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false)); 
      return e = null, !!d; 
    } 
}; 

function formatCurrency(o, n, dig, dec) { 
   o.c = !isNaN(n) ? Math.abs(n) : 2; 
   o.dec = typeof dec != "string" ? "," : dec, o.dig = typeof dig != "string" ? "." : dig; 
   addEvent(o, "keypress", function(e) { 
      if (e.key > 47 && e.key < 58) { 
         var o, s, l = (s = ((o = this).value.replace(/^0+/g, "") + String.fromCharCode(e.key)).replace(/\D/g, "")).length, n; 
         if(o.maxLength + 1 && l >= o.maxLength) return false; 
         l <= (n = o.c) && (s = new Array(n - l + 2).join("0") + s); 
         for(var i = (l = (s = s.split("")).length) - n; (i -= 3) > 0; s[i - 1] += o.dig); 
         n && n < l && (s[l - ++n] += o.dec); 
         o.value = s.join(""); 
      } 
      e.key > 30 && e.preventDefault(); 
   }); 
} 

function fmtMoney(n, c, d, t){ 
   var m = (c = Math.abs(c) + 1 ? c : 2, d = d || ",", t = t || ".", 
      /(\d+)(?:(\.\d+)|)/.exec(n + "")), x = m[1].length > 3 ? m[1].length % 3 : 0; 
   return (x ? m[1].substr(0, x) + t : "") + m[1].substr(x).replace(/(\d{3})(?=\d)/g, 
      "$1" + t) + (c ? d + (+m[2] || 0).toFixed(c).substr(2) : ""); 
}; 

function soma() { 
  var f = document.forms[0]; 
  var valor1 = parseFloat(f.campo1.value.replace('.','').replace(',','.')); 
  var valor2 = parseFloat(f.campo2.value=10); 
  var valor3 = ('' + ((valor1||0) / (valor2||0)));
  f.campo3.value = fmtMoney(valor3);
      
} 

function init() { 
  formatCurrency(document.forms[0].campo1, 2, ".", ","); 

 
  var valor1 = parseInt(document.forms[0].campo1.value) || 0; 
  var valor3 = parseInt(document.forms[0].campo3.value) || 0; 
  document.forms[0].campo4.value = valor1 + valor3; 
}  

window.onload = init; 
</script>
<HTML>

<HEAD>
<TITLE></TITLE>
<META NAME="GENERATOR" CONTENT="Sothink HTML Editor">
</HEAD>

<BODY>
<form> 
  Sub Total<input name="campo1" onkeyup="soma()" size="8" /> 
  <input name="campo2" onkeyup="soma()" size="8" / TYPE="Hidden"> 
  Valor do Frete<input name="campo3" size="8" />
  Total com o frete Frete<input name="campo4" size="8" />
  </form>



</BODY>
</HTML>
Desde ja agradeço a todos

Compartilhar este post


Link para o post
Compartilhar em outros sites

Resolvido

seque abaixo o script

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE></TITLE>

<META content="text/html; charset=windows-1252" http-equiv=Content-Type>

<META name=GENERATOR content="MSHTML 8.00.6001.18812">

<script language=javascript>

 

var nItens = 2;

 

function recalculaTotais(frm)

{

var total = 0;

var frete = 0;

var soma = 0;

for (var i = 0; i < nItens; i++)

{

frm.total.value = forma(Math.round(frm.preco.value * frm.quant.value ));

frm.frete.value = forma(Math.round(frm.quant.value * 1 ));

total+= parseFloat(frm.total.value.replace("R$",""));

frete+= parseFloat(frm.frete.value.replace("R$",""));

 

 

{

var total=total;

var frete=frete;

var Soma=((parseFloat(total))+(parseFloat(frete)));

frm.totalcomfrete.value=forma(Soma);

}

 

 

}

frm.totalgeral.value = forma(total)

frm.totalfrete.value = forma(frete)

 

 

 

}

function forma(num){

 

reais = Math.floor(num);

cents = Math.round((num-reais)*100);

texto = "R$" + reais + ",";

if(cents < 10){

texto = texto + "0";

}

texto = texto + cents;

 

return texto;

 

}

 

</SCRIPT>

</HEAD>

<BODY>

<FORM name=form>

<TABLE style="WIDTH: 599px; HEIGHT: 315px" VALUE="10">

<TBODY>

<TR>

<TH>Imagen

<TH>Códico

<TH>Produto

<TH>Preço

<TH>Quantidade

<TH>Frete

<TH>Total

<TR>

<TD><IMG style="WIDTH: 40px; HEIGHT: 31px" height=31 alt="" hspace=0

src="baixados1/001.JPG" width=40 border=0>

<TD>Cód.001

<TD SIZE="4" VALUE="R$10.00">Homem Aranha

<TD>R$ 15,00<INPUT id=preco onfocus=this.form.quant[0].focus() type=hidden

size=6 value=15.00 name=preco1>

<TD><INPUT id=quant onchange=recalculaTotais(this.form) size=4

name=quant1>

<TD><INPUT id=frete onfocus=this.form.quant[1].focus() size=8 value=R$0.00

name=frete1>

<TD><INPUT id=total onfocus=this.form.quant[1].focus() size=8 value=R$0.00

name=total1>

<TR>

<TD><IMG style="WIDTH: 40px; HEIGHT: 31px" height=31 alt="" hspace=0

src="baixados1/002.JPG" width=40 border=0>

<TD>Cód.002

<TD SIZE="4" VALUE="R$10.00">Flamengo

<TD>R$ 15,00<INPUT id=preco onfocus=this.form.quant[1].focus() type=hidden

size=6 value=15.00 name=preco2>

<TD><INPUT id=quant onchange=recalculaTotais(this.form) size=4

name=quant2>

<TD><INPUT id=frete onfocus=this.form.focus() size=8 value=R$0.00

name=frete2>

<TD><INPUT id=total onfocus=this.form.focus() size=8 value=R$0.00

name=total2>

 

<TR><!-- Finish thumbnail -->

<TD></TD>

<TD></TD>

<TD></TD>

<TD SIZE="9"></TD>

<TD TYPE="Hidden" SIZE="10" VALUE="R$0.00"></TD>

<TD><STRONG>Sub total:</STRONG> </TD>

<TD><INPUT id=totalgeral onfocus=this.form.focus() size=9 value=R$0.00

name=totalgeral></TD></TR>

<TD></TD>

<TD></TD>

<TD></TD>

<TD SIZE="9"></TD>

<TD TYPE="Hidden" SIZE="10" VALUE="R$0.00"></TD>

<TD><STRONG>Total do frete :</STRONG> </TD>

<TD><INPUT id=totalfrete onfocus=this.form.focus() size=9 value=R$0.00

name=totalfrete></TD></TR>

<TD></TD>

<TD></TD>

<TD></TD>

<TD SIZE="9"></TD>

<TD TYPE="Hidden" SIZE="10" VALUE="R$0.00"></TD>

<TD><STRONG>Total com o frete :</STRONG> </TD>

<TD><INPUT id=totalcomfrete onfocus=this.form.focus() size=9 value=R$0.00

name=totalcomfrete></TD></TR>

</TBODY></TABLE></TBODY></TABLE></FORM></BODY></HTML>

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.