Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/07/2011, 16:51
Avatar de maycolalvarez
maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 8 meses
Puntos: 1532
Respuesta: Entrada numérica compatible textbox con navegadores

no hace falta pasar el objeto, sino el event por la compatibilidad multinavegador, mi función:

Código Javascript:
Ver original
  1. var _chardecimal = '.';    //DEFINIR separador de la parte decimal
  2.  
  3. function inputFloat(e,minus){
  4.     var menos = minus || false;
  5.     if(e==null){
  6.         e=event;
  7.     }
  8.     if(e==null){
  9.         e=window.event;
  10.     }
  11.     var tecla = (document.all) ? e.keyCode : e.which;
  12.     //48=0,57=9, 45=menos
  13.     if(tecla==8)return true;//backs
  14.     if(tecla==_chardecimal.charCodeAt(0)) return true; //punto decimal
  15.     if (tecla==45){
  16.         if (!menos){
  17.             return false;
  18.         }
  19.     }else if(tecla < 48 || tecla > 57){
  20.         return false;
  21.     }
  22.     return true;
  23. }

uso
<input name="defecto" onKeyPress="return inputFloat(event)" type="text" size="10" />
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...