Kod
var LastInput=0, EmptyInput=0;
function AddFile()
{
var tmp, tmp2, files, new_input;
if(this.name.indexOf("file_")==0) { inputid = this.name.replace("file_", ""); tmp = this; }
else { inputid = 0; tmp = document.getElementsByName("file_0")[0]; }
if(tmp && tmp.value=='' && inputid!=EmptyInput)
{
tmp2 = document.getElementsByName("file_"+EmptyInput)[0];
files = document.getElementById("files");
//alert(tmp2);
if(files && tmp2) { files.replaceChild(tmp, tmp2); }
if(LastInput!=EmptyInput)
{
tmp2 = document.getElementsByName("file_"+LastInput)[0];
if(tmp2)
{
tmp2.setAttribute("name", "file_"+EmptyInput);
if(LastInput==inputid) inputid = EmptyInput;
}
}
EmptyInput = inputid;
--LastInput;
}
else if(tmp && tmp.value!='' && inputid==EmptyInput)
{
++LastInput;
EmptyInput = LastInput;
new_input = document.createElement("input");
new_input.setAttribute("type", "file");
new_input.setAttribute("name", "file_"+LastInput);
new_input.className = "textbox";
new_input.onchange = AddFile;
new_input.style.width = "400";
new_input.style.margin = "2px";
new_input.style.display = "block";
files = document.getElementById("files");
if(files) files.appendChild(new_input);
}
}
function AddFile()
{
var tmp, tmp2, files, new_input;
if(this.name.indexOf("file_")==0) { inputid = this.name.replace("file_", ""); tmp = this; }
else { inputid = 0; tmp = document.getElementsByName("file_0")[0]; }
if(tmp && tmp.value=='' && inputid!=EmptyInput)
{
tmp2 = document.getElementsByName("file_"+EmptyInput)[0];
files = document.getElementById("files");
//alert(tmp2);
if(files && tmp2) { files.replaceChild(tmp, tmp2); }
if(LastInput!=EmptyInput)
{
tmp2 = document.getElementsByName("file_"+LastInput)[0];
if(tmp2)
{
tmp2.setAttribute("name", "file_"+EmptyInput);
if(LastInput==inputid) inputid = EmptyInput;
}
}
EmptyInput = inputid;
--LastInput;
}
else if(tmp && tmp.value!='' && inputid==EmptyInput)
{
++LastInput;
EmptyInput = LastInput;
new_input = document.createElement("input");
new_input.setAttribute("type", "file");
new_input.setAttribute("name", "file_"+LastInput);
new_input.className = "textbox";
new_input.onchange = AddFile;
new_input.style.width = "400";
new_input.style.margin = "2px";
new_input.style.display = "block";
files = document.getElementById("files");
if(files) files.appendChild(new_input);
}
}
formularz:
<form method="post" enctype="multipart/form-data" onsubmit="document.getElementById('uploading').style.display='';"> <input type="hidden" name="action" value="upload"> <input type="hidden" name="dir" value=""> <div id="files"> <input type="file" name="file_0" class="textbox" onchange="AddFile();" style="width:400;margin:2px;display:block;"> </div> </form>
Aby zamiast uploadu było pole tekstowe (input type=text), próbowałem podmienić w samym formularzu ale wiele to nie pomaga, a javascript'a nie znam kompletnie...prosze o pomoc.
Pozdrawiam