Good
I have the following code that adds inputs conforming the number of inserted in a text box, however if the form already has some text boxes I just want it to add the difference, ie
start text box: 2
After change: altered text box - 3
At this point, as I have, I am adding 3 to what already exists,
Follow the code I have right now
$(document).ready(function() {
var $txtQuantidade = $('#txtQuantidade');
var $btnAdicionar = $('#btnAdicionar');
var $divForm = $('#divForm');
$btnAdicionar.on('click', function() {
var qtde = $txtQuantidade.val();
console.log(qtde);
var html = '';
for (var i = 0; i < qtde; i++) {
html += '<div>';
html += '<input type="date" id="txtData_' + i + '" name="data[]">';
html += '<input type="time" id="txtHoraIni_' + i + '" name="hinicio[]">'
html += '<input type="time" id="txtHoraFim_' + i + '" name="hfim[]">';
html += '<div>';
}
$divForm.append(html);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="text" id="txtQuantidade" />
<input type="button" id="btnAdicionar" value="Adicionar" />
<div id="divForm"></div>
I'll try to explain better:
Let's say I have 2 in the text box, I can only see two inputs, if I enter 3 then only I can show 3 inputs and finally if I put 2, I could only show 2 inputs by deleting a
Thank you