Does anyone know why, in my removeAdditionalFile function, the elements are not getting renamed? At least I think that's the problem. Although, if I use the remove link ONCE before uploading, it works ok. Using it TWICE before uploading is where the problem's at. Can anyone figure out what's wrong with my remove function?
function addFileTextbox()
{
var divLocation = document.getElementById('addToDiv');
var newDiv = document.createElement('div');
var count = document.getElementById('addToDiv').getElementsByTagName('input').length + 2;
var divIDName = 'file' + count;
var removeLinkID = 'removeLink' + count;
newDiv.innerHTML = '<input type="file" name="' + divIDName + '" id="' + divIDName + '" size="57"> <a href="#" id="' + removeLinkID + '" onclick="removeAdditionalFile(this.parentNode, ' + count + ')">Remove</a>';
divLocation.appendChild(newDiv);
var fileCount = document.getElementById('addToDiv').getElementsByTagName('input').length + 1;
document.getElementById('fileCount').value = fileCount;
}
function removeAdditionalFile(divIDNode, count)
{
var divLocation = document.getElementById('addToDiv');
divLocation.removeChild(divIDNode);
var fileCount = document.getElementById('addToDiv').getElementsByTagName('input').length + 1;
document.getElementById('fileCount').value = fileCount;
var nextFile = count + 1;
while (document.getElementById('file' + nextFile)) //there are file textboxes after the one deleted
{
//rename the file textbox, its ID, & the remove link's ID to be one less & change the count parameter of the remove link
document.getElementById('file' + nextFile).name = "file" + count;
document.getElementById('file' + nextFile).id = "file" + count;
document.getElementById('removeLink' + nextFile).onclick = function()
{
removeAdditionalFile(this.parentNode, ' + count + ');
}
document.getElementById('removeLink' + nextFile).id = "removeLink" + count;
nextFile++;
count++;
}
}
Click Browse to select a file on your computer, or type its path in the box below.<br />To upload multiple files at once, click Add.<br />
<input type="button" name="add" value="Add Another File" onclick="addFileTextbox();">
<form method="POST" name="fileForm" enctype="multipart/form-data" action="repos.exe">
File(s): <input type="file" size="66" name="file1" id="file1">
<input type="hidden" name="fileCount" id="fileCount" value="1">
<div id="addToDiv"></div> <!-- additional file textboxes will be added here -->
<input type="submit" name="submit" value="Upload">
</form>