Valeu Bruno pela tentativa, mas esse código e igualzinho ao que estou usando.
Tentei esse aí e continua o mesmo erro.
Erro: O objeto não dar suporte para propriedade ou metodo.
Você testou o código que eu postei dando ctrl+c e ctrl+v ?
porque eu tinha testado o que você postou e ele não estava funcionando (talvez porque na hora de copiar ele tenha colocado alguns caracteres estranhos…).
Esse código que eu postei está funcionando aqui na minha máquina…
pode ser alguma incompatibilidade com o browser …
Eu encontrei uma solução para deixar com 3 casas decimais para campo com 9 digitos, caso queira mais digitos basta implementar mais linhas e definir as posições.
Segue abaixo a função com minhas alterações.
function MascaraMoeda(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;
if (whichCode == 13 || 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 + '00' + aux;
if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + '0' +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);
[b] // VERIFICA O TAMANHO DO CAMPO PARA REFORMATAR COM A CASA DECIMAL COM 3 DIGITOS[/b]
if (aux.length == 4)
objTextBox.value = aux.substr(0, 1) + SeparadorDecimal + aux.substr(len - 3, len);
else if (aux.length == 5)
objTextBox.value = aux.substr(0, 2) + SeparadorDecimal + aux.substr(len - 3, 3);
else if (aux.length == 6)
objTextBox.value = aux.substr(0, 3) + SeparadorDecimal + aux.substr(len - 3, len);
else if (aux.length == 7)
objTextBox.value = aux.substr(0, 1) + SeparadorDecimal + aux.substr(len - 6, 3)+ SeparadorDecimal + aux.substr(len - 3, 3);
else if (aux.length == 8)
objTextBox.value = aux.substr(0, 2) + SeparadorDecimal + aux.substr(len - 6, 3)+ SeparadorDecimal + aux.substr(len - 3, 3);
else if (aux.length == 9)
objTextBox.value = aux.substr(0, 3) + SeparadorDecimal + aux.substr(len - 6, 3)+ SeparadorDecimal + aux.substr(len - 4, 3);
}
return false;