The basic code is in Preview an image before it is uploaded codes also are shown in below:
<script type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
<body>
<form id="form1" runat="server">
<input type='file' onchange="readURL(this);" />
<img id="blah" src="#" alt="your image" />
</form>
Codes work fine, but it shows broken image icon when there is no img is selected. I tried to use
if($('#img_prev').attr('src',"#"){
$('#img_prev').hide();
}
But it hides all images. Any help is welcome! Thank you for your time.