renaming input elements - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

renaming input elements

yssirhcyssirhc Posts: 2Member
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?

[code]
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 = ' Remove';
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++;
}
}
[/code]
[code]
Click Browse to select a file on your computer, or type its path in the box below.
To upload multiple files at once, click Add.





File(s):




[/code]
Sign In or Register to comment.