I have a page where the user can press a button that will append two new form inputs to the page. The user can do this as many times as necessary. The problem I am having is that I cannot seem to access the new inputs in the php file I am submitting to.
Here is the code for the button on the page the user sees. It is within a form.
<div class='instruction'>
<p>Please use the checkpoint tool to outline the primary steps
necessary for completion of the project.
<h4 style='margin-bottom:5px;'>Checkpoint Tool</h4>
<input type='button' onclick='addCheckpoint()' value='Add Checkpoint' />
<input type='text' id='count' name='projectCount' style='width:25px;' readonly='true' />
</p>
<div id='checkpoints'>
</div>
</div>
Here is the javascript function addCheckpoint()
function addCheckpoint()
{
var count = +document.getElementById('count').value;
// Declare Variables
var checkpointText = "Checkpoint "+(count+1);
var nameText = "Checkpoint Name: ";
var instructionText = "Instructions: ";
var previous = document.getElementById("checkpoints");
var newP = document.createElement("p");
var nameInput = document.createElement("input");
nameInput.setAttribute("type","text");
nameInput.setAttribute("name","checkpointName" + count);
var instructionInput = document.createElement("textarea");
instructionInput.setAttribute("name","checkpointInstruction" + count);
instructionInput.setAttribute("rows","4");
instructionInput.setAttribute("cols","56");
// Append Variables
newP.appendChild(document.createTextNode(checkpointText));
newP.appendChild(document.createElement("br"));
newP.appendChild(document.createElement("br"));
newP.appendChild(document.createTextNode(nameText));
newP.appendChild(nameInput);
newP.appendChild(document.createElement("br"));
newP.appendChild(document.createTextNode(instructionText));
newP.appendChild(instructionInput);
newP.appendChild(document.createElement("br"));
newP.appendChild(document.createElement("hr"));
previous.appendChild(newP);
document.getElementById('count').value = count + 1;
}
Here is the code on the page being submitted to that tries to retrieve the posted values.
$projectCount = strip_tags($_POST["projectCount"]);
for($i = 0; $i < $projectCount; $i += 1)
{
$checkpointNames[] = strip_tags($_POST["checkpointName".$i]);
$checkpointDescriptions[] = strip_tags($_POST["checkpointDescription".$i]);
}
I appreciate any help that can be offered!