[SOLVED] JavaScript creating table rows not working
Posted: Fri Aug 05, 2005 9:57 pm
Hello,
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:
Does anyone see any reason why this isn't working properly?
Thanks in advance,
Kyle
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:
Code: Select all
<html>
<head>
</head>
<body>
<script>
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 <= num_now; i++)
{
ff = i;
var x = document.getElementById('upload_list').insertRow(ff);
var y = x.insertCell(0);
var z = x.insertCell(1);
y.innerHTML = 'File ' + (numh + i) + ': ';
z.innerHTML = '<input type="file" name="f_' + i + '">';
}
document.getElementById('num_holder').value = parseInt(nf);
}
return true;
}
</script>
<table>
<tr>
<td>
<form action="" method="post" id="tform" onSubmit="create_input(); return false;">
How many files would you like to upload? <input type="text" id="num_files" value="1"/> <input type="submit" value="OK" />
<input type="hidden" id="num_holder" value="1"/>
<a href="javascript:alert(document.getElementById('num_holder').value);">Test</a>
</form>
<br />
<br />
<form enctype="multipart/form-data" action="index.php?action=upload2" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="{$max_size}" />
<table id="upload_list">
<tr><td>File 1: </td><td><input type="file" name="f_1"></td></tr>
</table>
<br />
<br />
<input type="submit" value="Upload Files" />
</form>
</td>
</tr>
</table>
</body>
</html>Thanks in advance,
Kyle