Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.