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?

1

1 Answer 1

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">

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.