I have this page that I made. You enter the number of files you want to upload and it creates that number of file inputs on the page. When you change the number to a bigger number than before it should add rows to the table. For some reason it is not working properly. Here is the code:
It doesnt enter the loop when when the difference is smaller than the current number of rows. If you increase from 5 to 7, the diff is 2 and so it doesnt enter the loop because your loop was 5 to 2 when it should have been 5 to 5+2.
function create_input()
{
var nf = document.getElementById('num_files').value;
var inp_cont = "";
if(nf > 20)
{
error_alert = alert("Sorry! You can only upload a maximum of 20 files at one time.");
}
else
{
var numh = document.getElementById('num_holder').value;
numh = parseInt(numh);
var num_now = parseInt(nf) - numh;
for (i = numh; i <= numh + num_now - 1; i++)
{
ff = i;
var x = document.getElementById('upload_list').insertRow(ff);
var y = x.insertCell(0);
var z = x.insertCell(1);
y.innerHTML = 'File ' + i + ': ';
z.innerHTML = '<input type="file" name="f_' + i + '">';
}
document.getElementById('num_holder').value = parseInt(nf);
}
return true;
}
Thank you very much Anjanesh. Now I am off to see if I can make it delete rows when I enter in a smaller number than what is kept in the holding variable.
Thank you again. I used your second bit of code as well. I'm 14 so these greater than/less than things take me some time to comprehend. I have to think for awhile and I get confused having 4 different things I could change. I had to subtract 1 from the row index in the delete loop so it would work properly.