Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/02/2007, 04:01
Avatar de JavierB
JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 23 años
Puntos: 772
Re: Convertir la primer letra de cada palabra en mayúscula

Hola alegna

En lugar de modificar el código que has puesto, he "creado" un nuevo. A ver si te sirve.

Pon así el cuadro de texto:

Código:
<input type="text" name="Nombre" id="nombre" maxlength="30" value="" onkeypress="return validar(event,this)" class="campo">
Y utiliza esta función:

Código:
function validar(e,solicitar){
  // Admitir solo letras
  tecla = (document.all) ? e.keyCode : e.which;
  if (tecla==8) return true;
  patron =/[\D\s]/;
  te = String.fromCharCode(tecla);
  if (!patron.test(te)) return false;
  // No amitir espacios iniciales y convertir 1ª letra a mayúscula
  txt = solicitar.value;
  if(txt.length==0 && te==' ') return false;
  if (txt.length==0 || txt.substr(txt.length-1,1)==' ') {
    solicitar.value = txt+te.toUpperCase();
    return false;
  } 
}
Saludos,

Última edición por JavierB; 11/02/2007 a las 04:22