0

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.

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by kracko
0
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..!

Edited by ko ko: Syntax wrong

0
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:)

1

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

0

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)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.