Duvidas mascara monetaria

1 resposta
carlos_maia

Bom dia pessoal,
tenho a seguinte duvida
Como eu poderia fazer em java script uma função de mascara monetária onde eu possa digitar um numero e ao inves de ele inserir na posiçao que eu cliquei ele coloca sempre no final.
Ex: Eu tenho o valor 1.000,00 no lugar do 1 eu quero colocar o valor 2 pra ficar assim 2.000,00 mas ele ta ficando assim
10.000,02
Abraços

funcao

function formataReais(fld, milSep, decSep, e) {

var sep = 0;

var key = ‘’;

var i = j = 0;

var len = len2 = 0;

var strCheck = -[telefone removido];

var aux = aux2 = ‘’;

var nome = window.navigator.appName;

var whichCode = (nome==Netscape) ? e.which : e.keyCode;

if (fld.value.length >= fld.maxLength && (whichCode != 13) && (whichCode != 8) && (whichCode == 45 )) whichCode = 1;

if (whichCode == 13 || whichCode == 0 || whichCode == 8 || whichCode == 45 ){

key = String.fromCharCode(whichCode);

if(fld.value.charAt(0)=="-"){

if(whichCode==8){
return true;

}

if(whichCode==0){

sairCampo()

return true;

}

return false;

}
if (whichCode==45){

fld.value=key+fld.value;

if(fld.value.charAt(0)=="-"){

return false;

}

}
return true;

}

key = String.fromCharCode(whichCode); // Valor para o código da Chave

y=fld.valueOf(key);

if (strCheck.indexOf(key) == -1) return false; // Chave inválida

len = fld.value.length;

for(i = 0; i < len; i++)

if ((fld.value.charAt(i) != 0) && (fld.value.charAt(i) != decSep)) break;

aux = ‘’;

for(; i < len; i++)

if (strCheck.indexOf(fld.value.charAt(i))!=-1){

aux += fld.value.charAt(i);

}

aux += key;

len = aux.length;

fld.value=mascaraMonetarioNegativo(aux.toString())

return false;
}

<html:text property=“vlFixoPorcent” styleClass=“inputValor”
styleId=‘valorFixoPorcent’ size=“14”
style=“text-align:right;” maxlength=“14” onkeypress=“return(formataReais(this,’.’,’,’,event));” />

Abraços

1 Resposta

Hellmanss

usa tag Code, está ilegivel :?

Criado 14 de maio de 2009
Ultima resposta 14 de mai. de 2009
Respostas 1
Participantes 2