Hello, anyone have any idea on how to display selected image in popup box? and then upload.
Currently, the basic way is to display the selected image in a <div> tag, and i want to change and display the image in popup/dialog/confirmation box.
Below is the code to select image, and display the preview image in <div>
<div class="item form-group">
<label class="control-label col-md-1 col-sm-1 col-xs-12" > </label>
<div class="col-md-2 col-sm-12 col-xs-12">
<label class="btn btn-primary btn-upload" for="img" data-toggle="tooltip" title="Upload image file">Select Image</label>
<input class="sr-only" id="img" name="img" type="file" accept="image/*">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-1 col-sm-1 col-xs-12"> </label>
<div class="col-md-2 col-sm-12 col-xs-12">
<div id ="image_display"></div>
</div>
</div>
The javascript
$(document).ready(function(){
var fileInput = document.getElementById('img');
var fileDisplayArea = document.getElementById('image_display');
fileInput.addEventListener('change', function(e) {
var file = fileInput.files[0];
var imageType = /image.*/;
if (file.type.match(imageType)) {
var reader = new FileReader();
reader.onload = function(e) {
fileDisplayArea.innerHTML = "";
var images = new Image();
images.src = reader.result;
fileDisplayArea.appendChild(images);
}
reader.readAsDataURL(file);
} else {
fileDisplayArea.innerHTML = "File not supported!"
}
});
});