I'm trying to get the code to work before the 7th textbox is added and once it has been added.
<!DOCTYPE html>
<html>
<head>
<title>Concatenate Words</title>
</head>
<body>
<script type="text/javascript">
function addNew()
{
document.getElementById("newBut").innerHTML = "<input type='text' id='tb7'>";
}
function concatenate()
{
concateText = document.getElementById("tb1").value + " " + document.getElementById("tb2").value + " " + document.getElementById("tb3").value + " " + document.getElementById("tb4").value + " " + document.getElementById("tb5").value + " " + document.getElementById("tb6").value + " " + document.getElementById("tb7").value;
document.getElementById("concateForm").value = concateText;
}
</script>
<h1>Please enter text into the fields below</h1>
<table>
<tr>
<td>
<input type="text" id="tb1">
</td>
</tr>
<tr>
<td>
<input type="text" id="tb2">
</td>
</tr>
<tr>
<td>
<input type="text" id="tb3">
</td>
</tr>
<tr>
<td>
<input type="text" id="tb4">
</td>
</tr>
<tr>
<td>
<input type="text" id="tb5">
</td>
</tr>
<tr>
<td>
<input type="text" id="tb6">
</td>
</tr>
<tr>
<td>
<div id="newBut">
</td>
</tr>
<tr>
<td>
<input type="text" name="textResult" id="concateForm" value="" onkeyup="concatenate()">
</td>
</tr>
<tr>
<td>
<input type="button" name="Add A New Box" value="Add an extra field" onclick="addNew()">
</td>
</tr>
</table>
</body>
The problem that i am having is that the code only works once the 7th text box has been added by clicking the button at the bottom. I was wondering whether it is possible to get the same function to work without the extra box added into the html code.