function addField() { let i = document.querySelectorAll('[name="answers"]').length; document.getElementById("choice_poll").insertAdjacentHTML('beforeEnd', '<input id="answers['+i+']" type="text" name="answers" value="">'); }