Inserir Inputs

by Jefferson Lima

HTML

<fieldset>
    <div id="exer2" style="height:auto;width:auto;">
        <input type="text" name="nomes" />
        <br/>
    </div>
    <button type="button" onclick="add()">+ Campo</button>
</fieldset>

JavaScript

function add() {
    var nome = document.getElementsByName('nomes');
    var i;
    var aux = nome.length;
    var conc = "";
    for (i = 0; i < aux; i++) {
        conc += "<input type='text' name='nomes' value='" + nome[i].value + "' /><br/>"
    }
    conc += "<input type='text' name='nomes' value='' /><br/>"
    document.getElementById('exer2').innerHTML = conc;

}