-2

FileReader

<div><img /></div>
<input name="picture[]" type="file" />
<div><img /></div>
<input name="picture[]" type="file" />

I have two or more div-input pairs(like above)
But I have no idea how to match them to preview own picture.

With JavaScript, please

Phiter
  • 12,987
  • 14
  • 45
  • 77
Matt_HYH
  • 11
  • 4

1 Answers1

0

I hope that this is good for you

  var loadFile = function(event) {
    var output = document.getElementById('output');
    output.src = URL.createObjectURL(event.target.files[0]);
  };

      
<input type="file" accept="image/*" onchange="loadFile(event)"><br>
<img id="output" src="">
Jack King
  • 231
  • 3
  • 14