How to Preview Image Before uploading using javascript in asp.net

<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]);
        }
    }
    $("#filePhoto").change(function () {
        readURL(this);
    });
   </script>

HTML as

Upload Photo:    <asp:FileUpload ID="FileUpload1" runat="server" onchange="readURL(this)" />
<img id="blah" src="#" alt="" style="height:150px; width:150px;"/>

No comments:

Post a Comment