Hi) I needed to make it possible for the user to upload many files from many directories of his pc to server. Here is the html and js code
html

<div id="addPhoto" >
Path and Title of the Photo.
<br /><br />
<input type="file" name="flImg0" />
<input type="text" name="txtTtl0" />
<input type="hidden" name="addN" value="0" />
</div>
<input type="button" value="Add another" name="btnAdd" onclick="AddMore();"/>

js

function AddMore()
{
var i = document.frmExhbt.addN.value;
i=parseInt(i);
i++;
document.frmExhbt.addN.value=i;
addPhoto.innerHTML = addPhoto.innerHTML +"<br/><input type='file' name='flImg'+ i>";
addPhoto.innerHTML = addPhoto.innerHTML +" <input type='text' name='txtTtl'+ i>";
}

This works for making more text fields and fields for uploading files. BUT, but when i select first file to upload, and then the second..the first one seems to disappear. Although the same doesn't happen for textfields. Thanks for help.

addPhoto.innerHTML = addPhoto.innerHTML +"<br/><input type='file' name='flImg'+ i>";

You need to insert the quote here <input type='file' name='flImg'" + i + "'>" This one may help you.

function AddMore()
{
var i = document.frmExhbt.addN.value;
var ele = document.getElementById('addPhoto');
i=parseInt(i);
i++;
document.frmExhbt.addN.value=i;
var newFile = document.createElement('DIV');
newFile.innerHTML = '<input type="file" name="flImg' + i + '" />';
newFile.innerHTML += '<input type="text" name="txtTtl' + i + '" />';
ele.appendChild(newFile);
}

Hope this help..!

addPhoto.innerHTML = addPhoto.innerHTML +"<br/><input type='file' name='flImg'+ i>";

You need to insert the quote here <input type='file' name='flImg'" + i + "'>" This one may help you.

function AddMore()
{
var i = document.frmExhbt.addN.value;
var ele = document.getElementById('addPhoto');
i=parseInt(i);
i++;
document.frmExhbt.addN.value=i;
var newFile = document.createElement('DIV');
newFile.innerHTML = '<input type="file" name="flImg' + i + '" />';
newFile.innerHTML += '<input type="text" name="txtTtl' + i + '" />';
ele.appendChild(newFile);
}

Hope this help..!

Well your notification is correct. It should be written that way..but that did not change the working way for file element. Thx for help anyway:)

The problem must be your PHP codes. Check your PHP codes or post here.

The problem must be your PHP codes. Check your PHP codes or post here.

) no, was not in php. Your code gave some help..instead of making new div element i simply needed to make new input element and append it on div) so thanks) solved)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.