Ver Mensaje Individual
  #4 (permalink)  
Antiguo 05/03/2008, 16:35
Avatar de derkenuke
derkenuke
Colaborador
 
Fecha de Ingreso: octubre-2003
Ubicación: self.location.href
Mensajes: 2.665
Antigüedad: 20 años, 6 meses
Puntos: 45
Re: Consulta de Evento onkeydown

Hola gersonmaba:

Vengo a solucionarte tus dudas:

En principio el código no funciona en ff porque no es estándar, está creado sólo para IE. Hay que tener en cuenta que el código sería event.which para sacar el código de tecla.

Y la solución para que no se coloque la tecla pulsada en la caja es sencilla, colocar un simple return false al final de la función:

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<
head>
<
meta http-equiv="Content-type" content="text/html;charset=iso-8859-1" />
<
meta name="Author" content="derkeNuke" />
<
title>Página nueva</title>
<
style type="text/css">

</
style>
</
head>

<
body>



<
input type='text' name='Logro_1_1' value='' size='1' maxlength='3' style='background-color:#F7F2BB; color:black' onkeydown='return ControTeclado(this, event);' />

<
input type='text' name='Logro_2_1' value='' size='1' maxlength='3' style='background-color:#F7F2BB; color:black' onkeydown='return ControTeclado(this, event);' />

<
input type='text' name='Logro_1_2' value='' size='1' maxlength='3' style='background-color:#F7F2BB;
color:black' 
onkeydown='return ControTeclado(this, event);' />




<
script type="text/javascript">
<!--


function 
ControTeclado(valev){
    if( 
window.event 
        var 
key window.event.keyCode;//codigo de tecla.
    
else
        var 
key ev.which;

    switch(
key){

        case 
97:
        
val.value='E';
        break;

        case 
98:
        
val.value='S';
        break;

        case 
99:
        
val.value='A';
        break;

        case 
100:
        
val.value='I';
        break;

        case 
101:
        
val.value='D';
        break;

        case 
40:
        
alert('abajo');
        break;

        case 
38:
        
alert('arriba');
        break;

    }

    return 
false;

}




// -->
</script>

</body>
</html> 

Espero que así se solucine. Un saludo.
__________________
- Haz preguntas inteligentes, y obtendrás más y mejores respuestas.
- Antes de postearlo Inténtalo y Búscalo.
- Escribe correctamente tus mensajes.