I have a problem collecting a number of an input that I have filled with ajax, the thing is that when I pick it up it is always returning 0. What can I do to get it back?
$(document).ready(function () {
eventosHoy();
});
// metodo que me crea los input
function eventosHoy() {
var dt = new Date(); // sacar la fecha de hoy
var month = dt.getMonth() + 1;
var day = dt.getDate();
var year = dt.getFullYear();
var fecha = month + '-' + day + '-' + year;
consulta = fecha;
var diaEventos = "";
$.ajax({
data: {"b": consulta},
type: "POST",
url: "servidor.php",
success: function (datos) { // es el parametro que te devuelve
s = JSON.parse(datos);
localStorage.setItem('eventosdia', s);
i = 0;
for (evento of s) { //aqui el array se pone al reves
//aqui formamos el html de cada evento
diaEventos = diaEventos + '<form name="formevento' + i + '" method="post" onSubmit="irEvento(this)">';
diaEventos = diaEventos + '<input type="text" id="pos" name="posicion" value="' + i + '">';
diaEventos = diaEventos + '<h1>Evento: ' + evento.descripcion + '</h1>';
diaEventos = diaEventos + '<h3>Hora: ' + evento.hora + '</h3>';
diaEventos = diaEventos + '<input type="submit" name="evento" name="boton" value="+info">';
diaEventos = diaEventos + '</form>';
i++;
}
$("#eventos").append(diaEventos);
}
});
//aqui quiero recuperar los input
function irEvento() {
console.log('hola');
var posicion = document.getElementById('pos').value;
alert(posicion);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<div id="eventos">
</div>
Thanks in advance.