Ir para conteúdo
Fórum Script Brasil

janiel14

Membros
  • Total de itens

    2
  • Registro em

  • Última visita

Tudo que janiel14 postou

  1. Andreia A função até funciona, mas não mantém o (. e ,) Aqui esta a função de formatação: /* * Formata Campo Moeda * SCRIPT: onKeyPress="return(formataMoeda(this,'.',',',event));" */ function formataMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){ var sep = 0; var key = ''; var i = j = 0; var len = len2 = 0; var strCheck = '0123456789'; var aux = aux2 = ''; var whichCode = (window.Event) ? e.which : e.keyCode; // 13=enter, 8=backspace as demais retornam 0(zero) // whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8)) return true; key = String.fromCharCode(whichCode); // Valor para o código da Chave if (strCheck.indexOf(key) == -1) return false; // Chave inválida len = objTextBox.value.length; for(i = 0; i < len; i++) if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break; aux = ''; for(; i < len; i++) if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i); aux += key; len = aux.length; if (len == 0) objTextBox.value = ''; if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux; if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux; if (len > 2) { aux2 = ''; for (j = 0, i = len - 3; i >= 0; i--) { if (j == 3) { aux2 += SeparadorMilesimo; j = 0; } aux2 += aux.charAt(i); j++; } objTextBox.value = ''; len2 = aux2.length; for (i = len2 - 1; i >= 0; i--) objTextBox.value += aux2.charAt(i); objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len); } return false; } Vou testar sem a formatação. obrigado pela força Navagadores: Internet Explorer 8, Firefox 3.5, Google Chrone Andreia, refiz meu codigo e consegui o resultado com precisão, agora preciso e formatar o resultado como moeda. segue o código abaixo: <script type="text/javascript"> function somaParcela() { var valor = document.forms['newParcela'].valor.value; var desconto = document.forms['newParcela'].desconto.value; var multa = document.forms['newParcela'].multa.value; var juros = document.forms['newParcela'].juros.value; var valor = valor.toString().replace( ".", "" ); var valor = valor.toString().replace( ",", "" ); var desconto = desconto.toString().replace( ".", "" ); var desconto = desconto.toString().replace( ",", "" ); var multa = multa.toString().replace( ".", "" ); var multa = multa.toString().replace( ",", "" ); var juros = juros.toString().replace( ".", "" ); var juros = juros.toString().replace( ",", "" ); var soma = parseFloat(valor)-parseFloat(desconto)+parseFloat(multa)+parseFloat(juros); if(soma == 0){ document.forms['newParcela'].valor.focus(); return false; } document.forms['newParcela'].total.value = eval(soma); //preciso colocar essa soma no formato moeda } </script>
  2. Pessoal, sou novato no forum mas tenho alguma experiência com programação php, mysql e javascript. recente estou trabalho em um sistema para minha empresa e me deparei com uma probleminha aqui com o seguinte codigo: function somaParcela() { var valor = document.forms['newParcela'].valor.value; var desconto = document.forms['newParcela'].desconto.value; var multa = document.forms['newParcela'].multa.value; var juros = document.forms['newParcela'].juros.value; var soma = parseFloat(valor)-parseFloat(desconto)+parseFloat(multa)+parseFloat(juros); document.forms['newParcela'].total.value = eval(soma); } </script> <form name="newParcela"> <input type="text" name="valor" value="" size="10" maxlength="11" onkeypress="return(formataMoeda(this,'.',',',event));" /><br> <input type="text" name="desconto" value="" size="10" maxlength="11" onkeypress="return(formataMoeda(this,'.',',',event));" /><br> <input type="text" name="multa" value="" size="10" maxlength="11" onkeypress="return(formataMoeda(this,'.',',',event));" /><br> <input type="text" name="juros" value="" size="10" maxlength="11" onkeypress="return(formataMoeda(this,'.',',',event));" /><br> <input type="text" name="total" value="" size="10" maxlength="11" onkeypress="return(formataMoeda(this,'.',',',event));" /><br> </form> E tambem uso uma função para formatar os campos. Mas o resultado da operação não e exata exemplo: valor: 10,90 - desconto: 0.40 + multa: 0,00 + juros:0,00 = 10.00 o correto seria: 10,50 Agradeço qualquer informação Atenciosamente Janiel Oliveira
×
×
  • Criar Novo...