Foros del Web » Programando para Internet » Javascript »

OnkeyPress y 2 funciones

Estas en el tema de OnkeyPress y 2 funciones en el foro de Javascript en Foros del Web. saludos tengo el sgte codigo Código: <html> <body> <script> function noNumbers(e) { var isNav = (navigator.appName.indexOf("Netscape") != -1) var isIE = (navigator.appName.indexOf("Microsoft") != -1) if ...
  #1 (permalink)  
Antiguo 22/10/2007, 13:51
Avatar de rol2007  
Fecha de Ingreso: mayo-2007
Ubicación: Santiasco CHILE
Mensajes: 300
Antigüedad: 17 años
Puntos: 4
De acuerdo OnkeyPress y 2 funciones

saludos tengo el sgte codigo
Código:
<html>
<body>
<script>

function noNumbers(e)
{
var isNav = (navigator.appName.indexOf("Netscape") != -1)
var isIE = (navigator.appName.indexOf("Microsoft") != -1)

	if (isNav) {
		//if ( e.which == 13 || evt.which == 8 || (evt.which >= 65 &&  e.which <=90) || (e.which >= 97 &&  e.which <=122) || e.which == 225 || e.which == 233 || e.which == 237 || e.which == 243 || e.which == 250 || e.which == 193 || e.which == 201 || e.which == 205 || e.which == 211 || e.which == 218 )
		if ( e.which == 209 || e.which == 241 || e.which == 13 || e.which == 8 || (e.which >= 65 &&  e.which <=90) || (e.which >= 97 &&  e.which <=122) || e.which == 32 )
		return true;
	return false;
	}
	else if (isIE)
		{e = window.event;
		//if ( e.keyCode == 13 || e.keyCode == 8 || (e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 225 || e.keyCode == 233 || e.keyCode == 237 || e.keyCode == 243 || e.keyCode == 250 || e.keyCode == 193 || e.keyCode == 201 || e.keyCode == 205 || e.keyCode == 211 || e.keyCode == 218 )
		if ( e.keyCode == 209 || e.keyCode == 241 || e.keyCode == 13 || e.keyCode == 8 || (e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32  )
			return true;
		return false;
		}
	else {
		alert("Su browser no es soportado por esta aplicación")
	}
	return false
}



function upperCase(e) { 
  tecla = (document.all) ? e.keyCode : e.which; 
  if(tecla == 9 || tecla == 0) return true; 
  if(tecla == 8) return true; 
  if(window.Event){ 
      var pst = e.currentTarget.selectionStart; 
      var string_start = e.currentTarget.value.substring(0,pst); 
      var string_end = e.currentTarget.value.substring(pst ,e.currentTarget.value.length); 
      e.currentTarget.value = string_start+ String.fromCharCode(tecla).toUpperCase()+ string_end; 
      e.currentTarget.selectionStart = pst + 1; 
      e.currentTarget.selectionEnd = pst + 1; 
      e.stopPropagation(); 
      return false; 
  } 
  else { 
    te = String.fromCharCode(tecla); 
    te = te.toUpperCase(); 
    num = te.charCodeAt(0); 
    e.keyCode = num; 
  } 
}

</script>


<input type="text" name="prueba" onkeypress="return upperCase(event); noNumbers(event)">




</body>
</html>


y no me funciona la 2da funcion por ke sera??? si podrian mirarlo porfa

se re agradece como siempre
:D
  #2 (permalink)  
Antiguo 22/10/2007, 14:43
 
Fecha de Ingreso: agosto-2004
Mensajes: 157
Antigüedad: 19 años, 8 meses
Puntos: 5
Re: OnkeyPress y 2 funciones

Hola rol2007

Puedes simplificar el código, quitando la función noNumbers, añadiendo una sola línea en la función uppercase.

Código:
<html>
<body>
<script>




function upperCase(e) { 
  tecla = (document.all) ? e.keyCode : e.which; 
  if(tecla == 9 || tecla == 0) return true; 
	if(/\d/.test(String.fromCharCode(tecla))) return false;
  if(tecla == 8) return true; 
  if(window.Event){ 
      var pst = e.currentTarget.selectionStart; 
      var string_start = e.currentTarget.value.substring(0,pst); 
      var string_end = e.currentTarget.value.substring(pst ,e.currentTarget.value.length); 
      e.currentTarget.value = string_start+ String.fromCharCode(tecla).toUpperCase()+ string_end; 
      e.currentTarget.selectionStart = pst + 1; 
      e.currentTarget.selectionEnd = pst + 1; 
      e.stopPropagation(); 
      return false; 
  } 
  else { 
    te = String.fromCharCode(tecla); 
    te = te.toUpperCase(); 
    num = te.charCodeAt(0); 
    e.keyCode = num; 
  } 
}

</script>


<input type="text" name="prueba" onkeypress="return upperCase(event)">




</body>
</html>
Si quiere utilizar varias funciones lo mejor es llamarlas dentro de una sola función.

Código:
<html>
<body>
<script>

function noNumbers(e)
{
var isNav = (navigator.appName.indexOf("Netscape") != -1)
var isIE = (navigator.appName.indexOf("Microsoft") != -1)

	if (isNav) {
		//if ( e.which == 13 || evt.which == 8 || (evt.which >= 65 &&  e.which <=90) || (e.which >= 97 &&  e.which <=122) || e.which == 225 || e.which == 233 || e.which == 237 || e.which == 243 || e.which == 250 || e.which == 193 || e.which == 201 || e.which == 205 || e.which == 211 || e.which == 218 )
		if ( e.which == 209 || e.which == 241 || e.which == 13 || e.which == 8 || (e.which >= 65 &&  e.which <=90) || (e.which >= 97 &&  e.which <=122) || e.which == 32 )
		return true;
	return false;
	}
	else if (isIE)
		{e = window.event;
		//if ( e.keyCode == 13 || e.keyCode == 8 || (e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 225 || e.keyCode == 233 || e.keyCode == 237 || e.keyCode == 243 || e.keyCode == 250 || e.keyCode == 193 || e.keyCode == 201 || e.keyCode == 205 || e.keyCode == 211 || e.keyCode == 218 )
		if ( e.keyCode == 209 || e.keyCode == 241 || e.keyCode == 13 || e.keyCode == 8 || (e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32  )
			return true;
		return false;
		}
	else {
		alert("Su browser no es soportado por esta aplicación")
	}
	return false
}



function upperCase(e) { 
  tecla = (document.all) ? e.keyCode : e.which; 
  if(tecla == 9 || tecla == 0) return true; 
	//if(/\d/.test(String.formCharCode(tecla)) return false;
  if(tecla == 8) return true; 
  if(window.Event){ 
      var pst = e.currentTarget.selectionStart; 
      var string_start = e.currentTarget.value.substring(0,pst); 
      var string_end = e.currentTarget.value.substring(pst ,e.currentTarget.value.length); 
      e.currentTarget.value = string_start+ String.fromCharCode(tecla).toUpperCase()+ string_end; 
      e.currentTarget.selectionStart = pst + 1; 
      e.currentTarget.selectionEnd = pst + 1; 
      e.stopPropagation(); 
      return false; 
  } 
  else { 
    te = String.fromCharCode(tecla); 
    te = te.toUpperCase(); 
    num = te.charCodeAt(0); 
    e.keyCode = num; 
  } 
}
function handlerEvents(event){

				 if(noNumbers(event)) upperCase(event);
				 else return false;

};
</script>


<input type="text" name="prueba" onkeypress="return handlerEvents(event); ">




</body>
</html>

Saludos
  #3 (permalink)  
Antiguo 22/10/2007, 14:50
 
Fecha de Ingreso: agosto-2004
Mensajes: 157
Antigüedad: 19 años, 8 meses
Puntos: 5
Re: OnkeyPress y 2 funciones

Hola de nuevo.

Olvide un return

Código:
function handlerEvents(event){

	 if(noNumbers(event))return upperCase(event);
	 else return false;

};

Saludos de nuevo.
  #4 (permalink)  
Antiguo 22/10/2007, 15:14
Avatar de rol2007  
Fecha de Ingreso: mayo-2007
Ubicación: Santiasco CHILE
Mensajes: 300
Antigüedad: 17 años
Puntos: 4
Re: OnkeyPress y 2 funciones

muchas muchas muchas gracias
te pasaste


buena idea eso de llamarlas mediante una funcion


caso cerrado
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:06.