Foros del Web » Programando para Internet » Javascript »

necesito un script!

Estas en el tema de necesito un script! en el foro de Javascript en Foros del Web. hola buenas pues eso, necesito un script en javascript, que lo que me haga esque en un formulario tengo el campo Nombre con su respectivo ...
  #1 (permalink)  
Antiguo 14/11/2005, 07:45
 
Fecha de Ingreso: abril-2005
Mensajes: 16
Antigüedad: 19 años
Puntos: 0
necesito un script!

hola buenas pues eso, necesito un script en javascript, que lo que me haga esque en un formulario tengo el campo Nombre con su respectivo input typo texto, y al final del formulario tengo un boton para enviar el formulario pues lo que necesito es que al darle al boton de enviar el texto que yo alla escribido en el input typo texto del Nombre se me coloque la primera letra de cada palabra si esque hay espacio en mayuscula, pongo un ejemplo:

Nombre: alvaro cerpa

y al darle al boton quiero que quede de la siguiente manera:

Nombre: Alvaro Cerpa


pd: espero que me ayuden gracias!! :D
  #2 (permalink)  
Antiguo 14/11/2005, 07:56
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
Hola el_caNela.... aquí esta:

Código HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<script language="javascript">
function Titulo() {
var obj = document.getElementById("titulo").value;
var obj_s = obj.split(" ");
 
for (i=0; i < obj_s.length; i++) {
primera_letra = obj_s[i].substring(0, 1).toUpperCase();
obj_s[i] = primera_letra + obj_s[i].substring(1, obj_s[i].length);
}
 
var nom = obj_s.join(" ");
alert(nom);
}
</script>
<input type="text" name="titulo" id="titulo" value="">
<input type="button" value="Cambiar Nombre" onClick="Titulo()">
</body>
</html> 
saludos
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #3 (permalink)  
Antiguo 14/11/2005, 07:58
 
Fecha de Ingreso: abril-2005
Mensajes: 16
Antigüedad: 19 años
Puntos: 0
pero una cosa saruman eso lo que me hace es al enviarlo me lanza un alert escribiendome la primera letra de cada palabra en mayuscula, pero lo que yo quiero esque se modifique en el campo, espera pongo mi codigo.

Código HTML:
<!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">
<head>
<title> Practica 10 </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

		<script language="javascript">  
    			var texto_estado = "                          Web caNela" 
  			var posicion = 1  
   			function mueve_texto(){ 
     			if (posicion < texto_estado.length) 
       				posicion ++; 
     			else 
       				posicion = 1; 
     				string_actual =texto_estado.substring(posicion) + texto_estado.substring(0,	 posicion) 
     				window.status =string_actual 
     				setTimeout("mueve_texto()",100) 
   			} 
			mueve_texto() 
		</script> 
		
		<script language="Javascript">

			function vacio()
			{ 
			
			var TELEFONO;
			TELEFONO=parseInt(document.formulario.Telefono.value,10);
			var EDAD;
			EDAD=parseInt(document.formulario.Edad.value,10);
			var telefono1;
			telefono1=document.formulario.Telefono.value;
			var edad1;
			edad1=document.formulario.Edad.value;
			
			if(document.formulario.Nombre.value=="")
			{
				alert("el campo nombre esta vacio");
				document.formulario.Nombre.focus();
			}
			
			else
			{		
				
				if(document.formulario.Apellido.value=="")
				{
        			alert("el campo apellido esta vacio");
					document.formulario.Apellido.focus();
				}
				
				else
				{
					
					if(document.formulario.Telefono.value=="")
					{
						alert("el campo telefono esta vacio");
						document.formulario.Telefono.focus();
					}
					
					if(isNaN(TELEFONO))
		 			{
		 			alert("el campo Telefono no es numerico");
					document.formulario.Telefono.value=""
					document.formulario.Telefono.focus();
		 			return true;
		 			}
					
					if(telefono1.length!=9)
					{
					alert("el telefono debe tener 9 digitos");
					document.formulario.Telefono.value="";
					document.formulario.Telefono.focus();
					return true;
					}	

					else
					{
						
						if(document.formulario.Edad.value=="")
						{
							alert("el campo edad esta vacio");
							document.formulario.Edad.focus();
						}
						
						if(isNaN(EDAD))
						{
							alert("el campo Edad no es numerico");
							document.formulario.Edad.value="";
							document.formulario.Edad.focus();
							return true;
						}

						if(edad1 > 100)
						{
							alert("la edad no puede superar a 100")
							document.formulario.Edad.value="";
							document.formulario.Edad.focus();
							return true;
						}
						
						else
						{
							if(document.formulario.Domicilio.value=="")
							{
								alert("el campo Domicilio esta vacio");
								document.formulario.Domicilio.focus();
							}
						}						
					}
				}
			}
			
			var obj = document.formulario.Nombre.value;
			var obj_s = obj.split(" ");
 
			for (i=0; i < obj_s.length; i++) 
			{
				primera_letra = obj_s[i].substring(0, 1).toUpperCase();
				obj_s[i] = primera_letra + obj_s[i].substring(1, obj_s[i].length);
			}
 
			var nom = obj_s.join(" ");
			alert(nom);
							
			}
		
		</script>

</head>
<body>

		
		<form name="formulario">
		<fieldset ID="Datos personales">
		<Legend ID="Datos personales"><Font size="5" color="orange">Datos Personales</Font></Legend>
		<TABLE Width="10" Height="15" name="tabla">
		<TR>
		<TD> <LABEL> <font color="black"> Nombre: </font> </LABEL> </TD><TD> <INPUT TYPE="TEXT" name=		"Nombre" Size="20" id="camponombre"></TD>
		</TR>
		<TR>
		<TD> <Label> <font color="black"> Apellido: </font> </label> </TD><TD> <INPUT Type="TEXT" Name="Apellido" Size="17"></TD>
		</TR>
		<TR>
		<TD> <label> <font color="black"> Telefono: </font> </label> </TD><TD> <INPUT Type="TEXT" Name="Telefono" Size="10"></TD>
		</TR>
		<TR>
		<TD> <label> <font color="black"> Edad: </font> </label> </TD><TD> <INPUT type="Text" Name="Edad" Size="2"></TD>
		</TR>
		<tr>
		<td> <label> <font color="black"> Domicilio </font> </label> </td><td> <input type="text" name="Domicilio" size="20"></td>
		</TABLE>
		<input type="button" value="confimacion de formulario" Onclick="vacio();">
		</fieldset>
		</form>

</body>
</html> 
pd: y si quisiera que en ved de darle al boton, quiero que lo haga automaticamente al quitar el foco del campo?

Última edición por el_caNela; 14/11/2005 a las 08:11
  #4 (permalink)  
Antiguo 14/11/2005, 08:15
Avatar de Cap.Buscapina  
Fecha de Ingreso: octubre-2004
Ubicación: Argentina
Mensajes: 836
Antigüedad: 19 años, 6 meses
Puntos: 4
hola,

aunque el amigo SARUMAN me ganó de mano (y casi con el mismo codigo), te pongo algo similar que hice y que te devuelve el valor al mismo input.

Cita:
<html>
<head>
<script>
function may(nn){
nombres=nn.value.split(" ");
for(x=0;x<nombres.length;x++){
nombres[x]=nombres[x].slice(0,1).toUpperCase( )+nombres[x].slice(1);
}
nn.value=nombres.join(" ");
}
</script>
</head>
<body>
<form action="formulario" method="get">
<input name="nombre" type="text" onkeyup="may(this)">
<input name="apellido" type="text" onkeyup="may(this)">

</form>
</body>
</html>
saludos
__________________
by Capitán Buscapina
.
  #5 (permalink)  
Antiguo 14/11/2005, 08:22
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
Cita:
Iniciado por el_caNela
pd: y si quisiera que en ved de darle al boton, quiero que lo haga automaticamente al quitar el foco del campo?
asi:

Código HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<script language="javascript">
function Titulo(obj) {
var obj_s = obj.value.split(" ");
 
for (i=0; i < obj_s.length; i++) {
primera_letra = obj_s[i].substring(0, 1).toUpperCase();
obj_s[i] = primera_letra + obj_s[i].substring(1, obj_s[i].length);
}
 
obj.value = obj_s.join(" ");
}
</script>
<input type="text" name="titulo" id="titulo" value="" onBlur="Titulo(this)">
<input type="button" value="Cambiar Imagen" onClick="Titulo()">
</body>
</html> 
pd. jejejeje Cap.Buscapina lo mismo la verdad
saludos a ambos
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #6 (permalink)  
Antiguo 14/11/2005, 10:10
 
Fecha de Ingreso: abril-2005
Mensajes: 16
Antigüedad: 19 años
Puntos: 0
muchisimas gracias este foro es la caña :D estare mucho por aqui que estoy estudiando lenguajes de programacion, asique tendre muchas dudas :D

gracias a ambos :D
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 09:55.