Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

misterviralata

[Resolvido] Tecla TAB só funciona no IE

Recommended Posts

Ola amigos!

 

To usando uma função que permiti que o usuario digite somente numeros no campo. Só que a tecla TAB não funciona como faço para libera-la?

 

<script>
function Numero(e){
navegador = /msie/i.test(navigator.userAgent);
if (navegador)
var tecla = event.keyCode;
else
var tecla = e.which;

if(tecla > 47 && tecla < 58) // numeros de 0 a 9
return true;
else{
if (tecla != 8) // backspace
return false;
else
return true;
}
}
</script>

<input type="text" name="campo" onKeyPress="return Numero(event);">

Tentei colocar assim, mas só funcionou no IE no Mozilla não!

<script>
function Numero(e){
navegador = /msie/i.test(navigator.userAgent);
if (navegador)
var tecla = event.keyCode;
else
var tecla = e.which;

if(tecla > 47 && tecla < 58) // numeros de 0 a 9
return true;
else{
if (tecla != 8) // backspace
return false;
else if (tecla == 9) // TAB
return true;
else
return true;
}
}
</script>

<input type="text" name="campo" onKeyPress="return Numero(event);">

Também tentei colocar assim e não funcionou no Mozila:

if(tecla > 47 && tecla < 58 || tecla == 9) // numeros de 0 a 9 e TAB

Obrigado!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Faça assim...

 

<html>
<head>
<title>Untitled Document</title>
<script>
function filtro(obj){
	if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 46){
		return true
	}else{
		return false
	}
}
</script>
</head>
<body>
<form name="form" method="get" action="teste.html">
	<input type="text" name="nome" onKeyDown="return filtro(this)">
</form>
</body>
</html>

essa função liberará somente as teclas numéricas, as setas para esquerda e para direita, backspace, delete e tab...

 

espero ter ajudado!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ola Leo Almeida!

 

Tentei usar o seu exemplo, mas ele também só funcionou no Internet Explorer, no Mozila além de não funcionar a tecla TAB, os campos aceitaram letras!

 

Tentei assim e também não deu certo:

 

function Numero(e){
navegador = /msie/i.test(navigator.userAgent);
if (navegador)
var tecla = event.keyCode;
else
var tecla = e.which;

if ((tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) || tecla == 8 || tecla == 9 || tecla == 37 || tecla == 39 || tecla == 46){
		return true
}else{
		return false
	}
}

Como faço para funcionar no MOZILLA?

Compartilhar este post


Link para o post
Compartilhar em outros sites

VALEU!!!!!

 

agora funcionou!!!

function Numero(e) {

	if (window.event){   //IE
		tecla = e.keyCode;
	} else if (e.which){ //FF
		tecla = e.which;
	}
	//teclas dos numemros(0 - 9) de 48 a 57
	//techa==8 é para permitir o backspace funcionar para apagar
	
	   if ( (tecla >= 48 && tecla <= 57)||(tecla == 8 ) ) {
		  return true;
		  }else{
		  return false;
		  }
}

Como é vcs encontram estes posts? eu procurando tanto e nunca acho!!!!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara.. fiz essa função aki pra você...

 

Ela funciona no IE e no FF.. TESTADO e APROVADO.

 

Função para apenas números no campo:

<script>
var numero;
function Valida(obj)
{
var valor = document.getElementById(obj).value;
var char = valor.substr(valor.length-1);
var numeros = new Array();
numeros[0] = "1";
numeros[1] = "2";
numeros[2] = "3";
numeros[3] = "4";
numeros[4] = "5";
numeros[5] = "6";
numeros[6] = "7";
numeros[7] = "8";
numeros[8] = "9";
numeros[9] = "0";

for (i=0;i<numeros.length;i++)
{
if(char == numeros[i])
{
numero = "sim";
break;
}
else
{
numero = "nao";
}
}


if (numero == "sim")
{
document.getElementById(obj).value = valor;
}
else
{
document.getElementById(obj).value = valor.substr(0,valor.length-1); 
}
}
</script>

<input type="text" name="nome" id = "lalala" onKeyUp="Valida('lalala')">

 

 

Espero ter ajudado...

 

Abraços...

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.