JavaScript - Enunciado Java Script

 
Vista:
sin imagen de perfil

Enunciado Java Script

Publicado por Gonzalo (9 intervenciones) el 11/10/2014 07:47:19
Validar que la edad sea numerica entera, el nombre no debe tener mas de 30 de caracteres, mayuscula.
Al terminar obtener: Cantidad de personas cuyo nombre empiezA con A, promedio generales de edades, porcentaje de personas
de cada estado civil.


Bien yo ya tengo hecho la parte visual

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<html>
		<head>
			<script>
				estado=new Array("Soltero","Casado","Viudo","Divorciado");
				guardar=new Array(5);
					function cargar()
						{
							nombre=document.f.txtNombre.value;
                                                        edad=document.f.txtEdad.value;
							estado=document.f.estado.value
 
 
							if(isNaN(edad))
								{
									alert("Error");
								}
 
 
						}
					function terminar()
						{
							document.write("Su nombre es :"+nombre+"<br>");
							document.write("Su edad es :"+edad+"<br>");
							document.write("Su estado civil es : "+estado)
						}
 
			</script>
		</head>
	<body>
			<form name="f">
				<table align="center">
					<caption><h1>Estado Civil</h1></caption>
						<tr>
							<td>Nombre :</td>
							<td><input type="text" name="txtNombre" maxlength="30"></td>
						</tr>
						<tr>
							<td>Edad :</td>
							<td><input type="text" name="txtEdad"></td>
						</tr>
						<tr>
							<td>Estado civil</td>
							<td>
								<select name="estado">
									<script>
										for(i=0; i<estado.length; i++)
											{
												document.write("<option value"+i+">"+estado[i]+"</option>");
											}
									</script>
								</select>
							</td>
						</tr>
						<tr align="center">
							<td colspan="2"><input type="button" value="Terminar" onClick="terminar()">
							<input type="button" value="Cargar" onClick="cargar()"></td>
						</tr>
				</table>
			</form>
	</body>
</html>

Lo que no se como se hace es que pueda ingresar tantos datos con el botón cargar y al finalizar tocar el botón terminar y me de todos los datos ingresados. Todavía no estamos trabajando con bases de datos, los datos guardados se guardan en un Array o bien una variable.

Después lo de validar lo puedo hacer tranquilamente yo.

Saludos espero su respuesta.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.162
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Enunciado Java Script

Publicado por xve (2100 intervenciones) el 11/10/2014 18:28:26
Hola Gonzalo, haber si te sirve este código que te he preparado...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<html>
	<head>
		<script>
			estado=new Array("Soltero","Casado","Viudo","Divorciado");
			guardar=new Array();
			function cargar()
			{
				var valores=new Array();
				valores.push(document.f.txtNombre.value);
				valores.push(document.f.txtEdad.value);
				valores.push(document.f.estado.value);
 
				if(document.f.txtNombre.value>30 || esNumero(document.f.txtEdad.value)==0)
				{
					alert("Error");
				}else{
					guardar.push(valores);
				}
				return false;
			}
			function terminar()
			{
				for(var i=0;i<guardar.length;i++)
				{
					document.write("Su nombre es :"+guardar[i][0]+"<br>");
					document.write("Su edad es :"+guardar[i][1]+"<br>");
					document.write("Su estado civil es :"+guardar[i][2]+"<br>");
				}
				return false;
			}
 
			function esNumero(value)
			{
				// Numero entero normal
				var patron=new RegExp("^([0-9])*$")
 
				if(value.search(patron)==0)
				{
					return 1;
				}
				return 0;
			}
		</script>
	</head>
	<body>
		<form name="f">
			<table align="center">
				<caption><h1>Estado Civil</h1></caption>
					<tr>
						<td>Nombre :</td>
						<td><input type="text" name="txtNombre" maxlength="30"></td>
					</tr>
					<tr>
						<td>Edad :</td>
						<td><input type="text" name="txtEdad"></td>
					</tr>
					<tr>
						<td>Estado civil</td>
						<td>
							<select name="estado">
								<script>
									for(i=0; i<estado.length; i++)
									{
										document.write("<option value"+i+">"+estado[i]+"</option>");
									}
								</script>
							</select>
						</td>
					</tr>
					<tr align="center">
						<td colspan="2"><input type="button" value="Terminar" onClick="return terminar();">
						<input type="button" value="Cargar" onClick="return cargar();"></td>
					</tr>
			</table>
		</form>
	</body>
</html>

Creo que cumple con todo... ya nos comentaras, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Enunciado Java Script

Publicado por Gonzalo (9 intervenciones) el 11/10/2014 20:03:52
Sos una masa, muchas gracias ahora me podre hacer lo otro.

Gracias!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar