I want to preview an image before it is uploaded.
I have tried many ways like this.
Image preview does not work.
I don't know where I did a mistake. I tried https://jsfiddle.net/lesson8/9NeXg/ and I have pasted my code.
Note : Fiddle Works fine, but when I copy fiddle to my page it did not work. I don't know what is my mistake.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<title>Untitled Document</title>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#image_upload_preview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#inputFile").change(function () {
readURL(this);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input type='file' id="inputFile" />
<img id="image_upload_preview" src="http://placehold.it/100x100" alt="your image" />
</form>
</body>
</html>