Reputation: 2129
I have two image fields (OR file field) on the page in a form.
I want to select an image from my computer in one image field, also gets selected into that second image field so that when I save the form, it also saved in that second image field.
Is it possible with jquery/javascript?
Upvotes: 0
Views: 79
Reputation: 1
It is not possible to set .files
property of <input type="file">
element. You can use FormData
to submit same image multiple times.
var fd = new FormData();
fd.append("file-1", file, file.name);
fd.append("file-2", file, file.name);
Upvotes: 0
Reputation: 136717
You can't change the input[type=file]
value
property, except to clear it, so this is also the only way to edit its files
property.
But you can use the FormData API for when you save your second form.
Then you just have to append(input2.name, input1.files[0])
in this FormData object.
Upvotes: 1