I am creating a website that will allow for a user-specified number of inputs. I want the user to be able to click a button and a new text and input box will appear that they can type in.
Here is my current code:
<!-- adds new company input field everytime button is clicked -->
<input type="button" onclick="addInput()">
<span id="companyX"></span><span id="companyBoxX"></span>
<script>
var countBox = 2;
var boxName = 0;
function addInput()
{
var boxName = "Company " + countBox;
var company = document.getElementById("companyX");
company.innerHTML += boxName;
var newBreak = document.createElement('br');
company.appendChild(newBreak);
document.getElementById('companyBoxX').innerHTML+='<br/><input type="text" id="'+boxName+'" value="'+boxName+'" " /><br/>';
countBox += 1;
}
</script>
Currently the problem is that everytime I try to add a new text or input field it just appends to the current text or input. I would like them to appear side by side each on a new line. Ex:
Company 1: (Input Box 1)
Company 2: (Input Box 2)
...
I am very new to Javascript and HTML and any help would be appreciated. Thanks!