Hello,
I'm really new to JavaScript and I found this script which creates/removes text boxes dynamically. It works except I want the name for each text box to be "stage 1", "stage 2", etc.
I can't seem to find a way to do it. I'm sure it's a small twist to it but any help?
----
I'm really new to JavaScript and I found this script which creates/removes text boxes dynamically. It works except I want the name for each text box to be "stage 1", "stage 2", etc.
I can't seem to find a way to do it. I'm sure it's a small twist to it but any help?
----
Code:
<script type="text/javascript">
function addTxtBx(){
var txtBxHolder = document.getElementById('txtBoxHolder');
var newTxtBx = document.createElement('input');
newTxtBx.type = 'text';
newTxtbx.name= 'stage' -<< the problem
txtBxHolder.appendChild(newTxtBx);
}
function removeTxtBx(){
var allTxtBxs = document.getElementById('txtBoxHolder').getElementsByTagName('input');
if(allTxtBxs.length == 0){
alert('There are no stages to remove.');
}
else{
document.getElementById('txtBoxHolder').removeChild(allTxtBxs[allTxtBxs.length-1]);
}
}
</script>
<div id="txtBoxHolder"></div>
<input type="button" value="Add stage" onclick="addTxtBx()">
<input type="button" value="Remove stage" onclick="removeTxtBx()">