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