Good morning!
I'm trying to create a kind of form.
The thing is that the user clicks on a button and different fields appear to fill in (these fields will be text-type inputs *).
Once filled out, click on a new button that has appeared next to the input text to save.
How do I put these fields in a array
? Do I have to have the array
previously created, or can I create it at the moment? The idea would be to have them in array
to then access it and take the data that interests me to work / show.
$(document).ready(function() {
// JS para crear rutinas estilo POWER
$('#Anyadir-Rutina-btn').click(function() {
// Hacemos aparecer la ventana modal donde rellenamos formulario.
$('#Modal-Escribir-Rutina').css({
'display': 'flex',
'height': 'auto',
'width': '80%'
});
// Creamos las variables donde se describen todos los elementos del formulario
var titulo1 = '<input type="text" placeholder="Titulo 1" id="Titulo1" />';
var titulo2 = '<input type="text" placeholder="Título 2" id="Titulo2" />';
var guardarModalBtn = '<input type="button" value="Guardar" id="Guardar-modal-btn" />';
// Insertamos los elementos para que el usuario rellene el formulario
$('#Modal-Escribir-Rutina').append(titulo1);
$('#Modal-Escribir-Rutina').append(titulo2);
$('#Modal-Escribir-Rutina').append(guardarModalBtn);
// Botón guardar. Guarda y muestra los datos escritos en el formulario.
$('#Guardar-modal-btn').click(function() {
alert("Ahora debería guardar");
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Kiitos!