We help IT Professionals succeed at work.
Get Started

Reorder multi file names

lulu50
lulu50 asked
on
233 Views
Last Modified: 2015-07-23
Hi,

I have a javascript that allow the user to upload multiple files and removes files.

My code will add the files starting from 0 - what ever number of files need to upload.

for example:
name=file0
name=file1
name=file2
name=file3
name=file4

if I remove two of the uploaded files (file2, file3)
I want the javascript to rename my files and give me the total number of upload.

so the output should be:
name=file0
name=file1
name=file2

Result = 3 for the total number of uploaded files.

I removed two of the files and renamed them from 0 - 2


this is my code

var counter = 0;

function AddFileUpload()

{

     var div = document.createElement('DIV');

     div.innerHTML = '<input id="file' + counter + '" name = "file' + counter + 

                     '" type="file" />' +

                     '<input id="Button' + counter + '" type="button" ' + 

                     'value="Remove" onclick = "RemoveFileUpload(this)" />';

     document.getElementById("FileUploadContainer").appendChild(div);

     counter++;

}

function RemoveFileUpload(div)

{

//here I need to rename my input files because I removed one and get the total count of the uploaded files.

     document.getElementById("FileUploadContainer").removeChild(div.parentNode); 

}

     <table style="width:100%;border:1px solid #eeeeee;background-color:#f5f5f5;">
           <tr>
<td align="right" valign="top" style="width:10%;padding-right:5px;"><span style="color:#4a79a5;font-weight:normal;"> <span style="color:#4a79a5;font-weight:normal;"> Click to add files:</span></td>
                <td valign="top" colspan="6">                   
                     <input id="Button1" type="button" value="add" onclick = "AddFileUpload()" />
    <br /><br />
    <div id = "FileUploadContainer">
        <!--FileUpload Controls will be added here -->
    </div>
    <br />
                </td>
              </tr>    
        </table>

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Expert of the Year 2008
Top Expert 2008
Commented:
This problem has been solved!
Unlock 2 Answers and 17 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE