I have a code to allow to pre-visualise the picture selected in a form.
However it doesn't work, what shoul I change?
<input type="file" id="profile-img1" data-idpreview="image1">
<div id="image1"></div>
<input type="file" id="profile-img2" data-idpreview="image2">
<div id="image2"></div>
function readURL(input) {
if (input.files && input.files[0]) {
var idPreview = $(input).attr('data-idpreview');
var reader = new FileReader();
reader.onload = function (e) {
$('#' + idPreview).css('backgroundImage', "url(" + e.target.result + ")" );
}
reader.readAsDataURL(input.files[0]);
}
}
input.onchange = readURL