3
How do I preview several different images from different inputs?
Here’s an example of how I wanted it to stay
HTML
<div class="col">
<input type="file" class="custom-file-input" name="arquivo" id="files" onchange="preview(this);">
<div class="preview-img">
<img id="preview_image" alt="" src="">
</div>
</div>
<div class="col">
<input type="file" class="custom-file-input" name="arquivo" id="files" onchange="preview(this);">
<div class="preview-img">
<img id="preview_image" alt="" src="">
</div>
</div>
<div class="col">
<input type="file" class="custom-file-input" name="arquivo" id="files" onchange="preview(this);">
<div class="preview-img">
<img id="preview_image" alt="" src="">
</div>
</div>
Javascript
function preview(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#preview_image')
.attr('src', e.target.result)
.width(100)
.height(100)
};
reader.readAsDataURL(input.files[0]);
}
}
Hello Altemberg. I edited the question to include the relevant code right here. It is always important to do this, so that people do not need to leave the site to understand the problem. In addition, external links may be unavailable. Please take this into account in the next questions, and good learning!
– bfavaretto