1
Guys, I built a dynamic form using JS. Inside this form I have several input with the class data
, where I call datepicker. But they don’t work, someone can help me with this?
Follow the example below. Note that in non-dynamic input datepicker works.
$('.data').datepicker({
'autoclose': true
});
function adicionarCampos() {
var objSelect = document.getElementById("numParcelas");
var i;
var linha = "";
// Cria os input
for (i = 0; i < objSelect.value; i++) {
// Monta HTML
linha += "\
<input type='text' name='data" + i + "' id='linha" + i + "' class='data' maxlength='10'>\n\
";
}
document.getElementById("txtParcelas").innerHTML = linha;
}
// Chama o evento
window.onload = adicionarCampos;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
Aqui o datepicker funciona
<input type='text' class='data'>
<br><br><br><br>
Gera o formulário
<input type='text' id='numParcelas' name='numParcelas' OnKeyUp="adicionarCampos()" value="1">
<br>
Aqui o datepicker não funciona<br>
<span id="txtParcelas"></span>
Thank you very much, it worked 100%
– Hugo Borges