Archive for July 2013
Fileupload preview image using javascript
CSS :
<style>
#imgPreview
{
filter: progidXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
width: 136px;
height: 134px;
margin-left: 1px;
}
</style>
Script:<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script> function PreviewImg(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $('#imgPreview').attr('src', e.target.result); } reader.readAsDataURL(input.files[0]); } } </script>
HTML :<asp:FileUpload ID="file" runat="server" size="20" Width="258px" onchange="PreviewImg(this)"/> <img id="imgPreview" src="#"/>