2
 Followers
2
 Likes

Image preview using javascript

Frontend
On our radar

SyntaxEditor Code Snippet

$('input[id*=Image1]').change(function(){
   readURL(this);
});
});
function readURL(input) {
        debugger;
        var validExtensions = ['jpg','png','jpeg']; //array of valid extensions
        var fileName = input.files[0].name;
        var fileNameExt = fileName.substr(fileName.lastIndexOf('.') + 1);
        if ($.inArray(fileNameExt, validExtensions) == -1) {
            input.type = ''
            input.type = 'file'
            alert("Only these file types are accepted : "+validExtensions.join(', '));
        }
        else
        {
        if (input.files && input.files[0]) {
            var filerdr = new FileReader();
            filerdr.onload = function (e) {
                $('.ImgReviewClass').attr('src', e.target.result);
            }
            filerdr.readAsDataURL(input.files[0]);
        }
        }
    }
Created on 8 Dec 2017
Comments (0)
views
307
Followers
2