Assuming you are using jQuery, I have following solution for you (sorry for the code formatting) :-->.
$(document).ready(function(){ $('input[type=file]').on('change', setImage); });
}); function setImage(file) { if(document.all) {
document.getElementById('prevImage').src = file.value;
}
else{ document.getElementById('prevImage').src = file.files.item(0).getAsDataURL();
}
{ document.getElementById('prevImage').src = file.value; } else { document.getElementById('prevImage').src = file.files.item(0).getAsDataURL(); } if(document.getElementById('prevImage').src.length > 0) { document.getElementById('prevImage').style.display = 'block'; } } }