girionis
asked on
Populate a file input type on load.
Hello, I have created a dynamic form where the user can add several files for upload. This form is a popup to the main form. When the user clicks submit on the popup form I do not upload the files straight away but rather I save the info in a hidden variable. When the user changes his mind and goes back to the file upload popup form again I would like to display on the file input fields the values he previously selected. However for some reason it does not seem to work. The way I create the dynamic form is the following:
//create a new input object--this is the actual textbox
obj=document.createElement ("input");
//give it a type
obj.type="file";
// give it a size
obj.size="75";
//give it an id
obj.id="file"+cnt;
//add the object to the form
frm.appendChild(obj);
//create a new line break object (<br/>)
obj=document.createElement ("br");
//add the object to the form
frm.appendChild(obj);
When the popup appears I try append the previously input values but to no avail. The way I try to make it is the following:
obj.value=fileNamesArray[i ];
where the fileNamesArray variable holds all the file names to be uploaded. I am sure there are filenames in the array since in the beginning of the for loop I have an alert box and it displays the file names correctly:
alert(fileNamesArray[i]);
Any help is more than welcome.
//create a new input object--this is the actual textbox
obj=document.createElement
//give it a type
obj.type="file";
// give it a size
obj.size="75";
//give it an id
obj.id="file"+cnt;
//add the object to the form
frm.appendChild(obj);
//create a new line break object (<br/>)
obj=document.createElement
//add the object to the form
frm.appendChild(obj);
When the popup appears I try append the previously input values but to no avail. The way I try to make it is the following:
obj.value=fileNamesArray[i
where the fileNamesArray variable holds all the file names to be uploaded. I am sure there are filenames in the array since in the beginning of the for loop I have an alert box and it displays the file names correctly:
alert(fileNamesArray[i]);
Any help is more than welcome.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It works on Opera 7.23 final for Linux. But you are right, it does not work under Netscape, Mozilla and IE. So it's a bug in Opera then. I will file a bug report.
I will accept the answers then since there is nothing I can do about it.
I will accept the answers then since there is nothing I can do about it.
ASKER
Thank you both :)
You are welcome...
Michel
Michel
ASKER
<input type="file" name="fileName" value="c:\documents and settings\private files\passwordlist"/>