Ver Mensaje Individual
  #2 (permalink)  
Antiguo 20/11/2002, 14:18
Avatar de Kaopectate
Kaopectate
Colaborador
 
Fecha de Ingreso: diciembre-2001
Ubicación: Curaçao (Antillas Holandesas)
Mensajes: 3.179
Antigüedad: 23 años, 2 meses
Puntos: 38
Muy bueno el script, me dió dolor trasquilarlo. En algún momento lo generalizo para pasarle como parámetro el número de decimales.

Bueno, de cualquier modo es asi:

Código PHP:
<html>
 <
head>
  <
script language="JavaScript">
   function 
currencyFormat(fldmilSepdecSepe) {
    var 
sep 0;
    var 
key '';
    var 
0;
    var 
len len2 0;
    var 
strCheck '0123456789';
    var 
aux aux2 '';
    var 
whichCode = (window.Event) ? e.which e.keyCode;
    if (
whichCode == 13) return true// Enter
    
key String.fromCharCode(whichCode); // Get key value from key code
    
if (strCheck.indexOf(key) == -1) return false// Not a valid key
    
len fld.value.length;
    for(
0leni++)
     if ((
fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
    
aux '';
    for(; 
leni++)
     if (
strCheck.indexOf(fld.value.charAt(i))!=-1aux += fld.value.charAt(i);
    
aux += key;
    
len aux.length;
    
aux2 '';
    for (
0len 1>= 0i--) {
     if (
== 3) {
      
aux2 += milSep;
      
0;
     }
     
aux2 += aux.charAt(i);
     
j++;
    }
    
fld.value '';
    
len2 aux2.length;
    for (
len2 1>= 0i--)
     
fld.value += aux2.charAt(i);
    return 
false;
   }
  
</script>
 </head>
 <body>
  <form>
   Enter Value: 
   <input type="text" name="test" length="15" 

onKeyPress="return(currencyFormat(this,',','.',event))">
  </form>
 </body>
</html> 
Saludos.