Código de JavaScript - Lista de contactos en JavaScript

Versión 1
estrellaestrellaestrellaestrellaestrella(2)

Actualizado el 17 de Junio del 2015 (Publicado el 15 de Junio del 2015)gráfica de visualizaciones de la versión: Versión 1
11.537 visualizaciones desde el 15 de Junio del 2015
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!doctype html>
<html>
<head>
	<script>
	var count=0;
 
	/**
	 * función para agregar valores a la tabla
	 */
	function agregarValores(){
		// cogemos los valores del formulario
		var nombre=document.getElementById("nombre").value;
		var apellidos=document.getElementById("apellidos").value;
		var correo=document.getElementById("correo").value;
 
		// La variable cont, genera un id unico para cada contacto
		// Este id es el utilizado para eliminar-lo
		count++;
 
		if(nombre.length>0 || apellidos.length>0)
		{
			var tbody = document.getElementById("miTabla").getElementsByTagName("TBODY")[0];
 
			var attrId = document.createAttribute('id');
			attrId.value=count;
 
			var td1 = document.createElement("TD");
			td1.appendChild(document.createTextNode(nombre));
			var td2 = document.createElement("TD");
			td2.appendChild(document.createTextNode(apellidos));
			var td3 = document.createElement("TD");
			td3.appendChild(document.createTextNode(correo));
			var td4 = document.createElement("TD");
			td4.appendChild(crearButton(count));
 
			var row = document.createElement("TR");
			row.setAttributeNode(attrId);
			row.appendChild(td1);
			row.appendChild(td2);
			row.appendChild(td3);
			row.appendChild(td4);
			tbody.appendChild(row);
		}
 
		// Eliminamos los valores del formulario
		document.getElementById("nombre").value="";
		document.getElementById("apellidos").value="";
		document.getElementById("correo").value="";
	}
 
	/**
	 * Función para eliminar un valor de la tabla
	 */
	function eliminarValor(id)
	{
		var row = document.getElementById(id);
		row.parentNode.removeChild(row);
	}
 
	/**
	 * Función que crea el boton de eliminar
	 * Tiene que recibie el id a eliminar
	 */
	function crearButton(id)
	{
		var button=document.createElement("input");
		var attrType=document.createAttribute('type');
		attrType.value="button";
		var attrValue=document.createAttribute('value');
		attrValue.value="Eliminar";
		var attrOnclick=document.createAttribute('onclick');
		attrOnclick.value="eliminarValor("+count+");";
 
		button.setAttributeNode(attrType);
		button.setAttributeNode(attrValue);
		button.setAttributeNode(attrOnclick);
 
		return button;
	}
	</script>
 
	<style>
	#miTabla {border:1px solid #ddd;padding: 10px;}
	#miTabla thead tr td {font-weight:bold;padding:10px;}
	#miTabla tbody tr:nth-child(odd) {background-color:#f8f8f8;}
	#miTabla tr {}
	#miTabla td {padding:5px;}
 
	form {width:300px;text-align:center;}
	form label {display:inline-block;width:100px;text-align:right;}
	</style>
</head>
 
<body>
 
<table id="miTabla">
	<thead>
		<tr>
			<td>Nombre</td>
			<td>Apellidos</td>
			<td>Correo</td>
		</tr>
	</thead>
	<tbody>
	</tbody>
</table>
 
<p>
	<form>
		<label>Nombre:</label> <input type="text" id="nombre">
		<label>Apellidos:</label> <input type="text" id="apellidos">
		<label>Correo:</label> <input type="text" id="correo">
		<p>
			<input type="button" onclick="agregarValores();" value="Agregar">
		</p>
	</form>
</p>
 
</body>
</html>



Comentarios sobre la versión: Versión 1 (2)

19 de Junio del 2015
estrellaestrellaestrellaestrellaestrella
No ha dejado ningún comentario
Responder
Angel
2 de Octubre del 2016
estrellaestrellaestrellaestrellaestrella
No ha dejado ningún comentario
Responder

Comentar la versión: Versión 1

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s3191