I have the following problem: I created a button that generates two input fields inside a form, the problem is that when the refresh page the generated fields disappear. I would like to know how do I make them once generated remain in the form until they are deleted via exclusion button (Still to be developed ^^ ")
Here are the codes:
var line = 1;
function addInput(divName) {
var newdiv = document.createElement('div');
newdiv.innerHTML = '['+line +']';
newdiv.innerHTML += '<div class="row"><div class="col-md-6"><label>Quando alguém disser:</label><input type="text" name="leitura'+line +'_1" id="leitura'+line +'_1"><br></div><div class="col-md-6"><label>O bot deve responder:</label><input type="text" name="resposta'+line +'_2" id="resposta'+line +'_2"><br></div></div><br>';
document.getElementById(divName).appendChild(newdiv);
line++;
}
addInput('lines');
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-xl-8 offset-xl-2 py-3">
<form id="form">
<button type="button" onclick="addInput('lines')">+ Adicionar Resposta</button>
<br><br>
<div id="lines"></div>
</form>
</div>
</div>
</div>