0

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]);
  }
}
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.