dynamic <form><file>-elements

M

Martin Nadoll

Hello,

i want a user-form for file upload.
i dont know, how many files the user want to upload, so i want to start with
only three buttons:

<table id="imgbin" colspan="2"><tr><td>
<input type="button" onclick="insertInput('imgbin','Bild')" value="add img">
</td></tr></table>

<table id="videobin" colspan="2"><tr><td>
<input type="button" onclick="insertInput('videobin','Video')" value="add
video">
</td></tr></table>

<table id="swfbin" colspan="2"><tr><td>
<input type="button" onclick="insertInput('swfbin','Flash')" value="add
flash">
</td></tr></table>

<script>
var bildnr = 0;
var videonr = 0;
var swfnr = 0;
function insertInput(id,f) {
var zahl='';
if(f=='Bild') { bildnr+= 1; zahl=bildnr; }
if(f=='Video') { videonr+= 1; zahl=videonr; }
if(f=='Flash') { swfnr+= 1; zahl=swfnr; }
var x=document.getElementById(id).insertRow(zahl+1);
var y=x.insertCell(0);
var z=x.insertCell(1);
y.innerHTML=f;
z.innerHTML+="<input type=\"file\" name=\""+f+zahl+"\">";
}
</script>

now. when i click my "add file", a new <tr> appears with my <file>-field.
everything ok so far.
i expected to generate:
<file type="file" name="Bild1">
<file type="file" name="Bild2"> and so on...
but when i submit my form, there is no "post"-data transfered to my next
page.
do i have the wrong idea here?

maybe , someone can help me, maybe to improve my idea or to lead me to a
other, better solution.

thanks a lot,
martin nadoll
 
T

Tim Slattery

Martin Nadoll said:
Hello,

i want a user-form for file upload.
i dont know, how many files the user want to upload, so i want to start with
only three buttons:

<table id="imgbin" colspan="2"><tr><td>
<input type="button" onclick="insertInput('imgbin','Bild')" value="add img">
</td></tr></table>

now. when i click my "add file", a new <tr> appears with my <file>-field.
everything ok so far.
i expected to generate:
<file type="file" name="Bild1">
<file type="file" name="Bild2"> and so on...
but when i submit my form, there is no "post"-data transfered to my next
page.
do i have the wrong idea here?

I don't see a <form..> tag, as Martin noted. I also don't see anyplace
where you submit the form. You're using <input type="button"..>, but
clicking that doesn't submit the form. You need to use <input
type="submit"...> or have your Javascript function submit the form.

Also look here:
http://the-stickman.com/web-development/javascript/multiple-file-uploader-mootools-12-version/

This guy has done exactly what you're trying to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top