I made a form where a button calls the function "addproduct ()" In this function I create 1 div and 2 textbox that are placed in the same div, and then add the div to a span at the bottom of the page.
The function works perfectly when it comes to adding div and textboxes, but when I click the button again and one of the textboxes added previously is already filled, what is written goes out and it goes blank.
I have no idea why this occurs, I thought it was because the names of the textboxes are arranged as an array, but it looks like it is not. here is the code:
var contador = 1;
function addproduto()
{
var div = document.createElement("div");
contador = contador + 1;
var nome = document.createElement("input");
var qtd = document.createElement("input")
div.setAttribute("id", contador);
nome.setAttribute("type", "text");
nome.setAttribute("name", "nome[]");
qtd.setAttribute("type", "text");
qtd.setAttribute("name", "qtdprod[]");
var spanlugar = document.getElementById("lugar");
//coloca os elementos no ultimo lugar da nova div e entre eles os textos
div.innerHTML = div.innerHTML + "Nome do produto " + contador + ":" ;
div.appendChild(nome);
div.innerHTML = div.innerHTML + "<br> Quantidade:";
div.appendChild(qtd);
//colca o div no ultimo lugar do span.
spanlugar.appendChild(div);
spanlugar.innerHTML = spanlugar.innerHTML + "<br>";
}