¿Cómo almacenar INPUT por teclado tipo text en ARRAY -HTML?
Publicado por Greta_valencia (1 intervención) el 28/04/2020 20:06:00
Hola,
Estoy intentado hacer el siguiente ejercicio:
*Haz una web con un input de tipo texto y dos botones “Añadir” y “Mostrar”. Al pulsar el
botón “Añadir”, se añadirá el contenido del input a un array vacío previamente creado (definir como
variable global) y borrará el input ( document.forms["nomForm"] ["nomInput"].value = "" ). Al
pulsar el botón “Mostrar”, se mostrará la lista de todos los elementos, uno por línea*
Pero no sé cómo debo hacer para que se guarde tipo ARRAY...
De momento tengo:
Gracias de antemano.
Saludos.
Estoy intentado hacer el siguiente ejercicio:
*Haz una web con un input de tipo texto y dos botones “Añadir” y “Mostrar”. Al pulsar el
botón “Añadir”, se añadirá el contenido del input a un array vacío previamente creado (definir como
variable global) y borrará el input ( document.forms["nomForm"] ["nomInput"].value = "" ). Al
pulsar el botón “Mostrar”, se mostrará la lista de todos los elementos, uno por línea*
Pero no sé cómo debo hacer para que se guarde tipo ARRAY...
De momento tengo:
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
<body>
<form name="tercero" method="post">
<label for="texto">Escribe un texto:</label><br>
<input type="text" id="texto" name="texto" maxlength="35"><br>
<button type="button" onclick="añadir()">AÑADIR</button>
<button type="button" onclick="mostrar()">MOSTRAR</button>
<p id="demo"></p>
</form>
<script>
function añadir(){
var arraytexto = [];
document.getElementById('demo').innerHTML=arraytexto;
}
}
function mostrar(){
document.getElementById("demo").innerHTML = arraytexto.join("*");
}
</script>
</body>
</html>
Gracias de antemano.
Saludos.
Valora esta pregunta


0