3

Is there a way to use JavaScript to set the file name and contents of a form's file uploads?

For example, suppose we have two file input elements.

<input type="file">
<input type="file">

Can JavaScript copy the content from one form element to the other?

Eric Willigers
  • 1,710
  • 14
  • 9
  • Possible duplicate of [How to set a value to a file input in HTML?](https://stackoverflow.com/questions/1696877/how-to-set-a-value-to-a-file-input-in-html) – Bibimission May 15 '18 at 08:52

1 Answers1

1

Add an onchange event on any of the input type file

Get its file property and assign to other input like

element2.files = element1.files;

var el = document.getElementById("1");
var el1 = document.getElementById("2");
el.onchange = function(){
el1.files = el.files;
 

}
<input type="file" id="1">
<input type="file" id="2">
Muhammad Usman
  • 10,039
  • 22
  • 39