Image preview before upload with javascript & jquery step by step

  • Brijpal Sharma

    June 03rd, 2019 , Posted On:- Web Development

    html javascript

This post describes you how to preview an image on before uploading to the server by using javascript step by step. using FileReader and jquery.

Image preview before upload with javascript & jquery step by step

Image preview is very important function while client upload image. some time client what to know what image uploading.

<!DOCTYPE html>
    <title>Image Preview</title>
<body style="background: lightgrey">
    <img id="preview" src="" width="350px" height="320px"/><br/>
    <input type="file" id="image" style="display: none;"/>
    <!--<input type="hidden" style="display: none" value="0" name="remove" id="remove">-->
    <a href="javascript:changeProfile()">Change</a> |
    <a style="color: red" href="javascript:removeImage()">Remove</a>
<script src=""></script>
    function changeProfile() {
    $('#image').change(function () {
        var imgPath = this.value;
        var ext = imgPath.substring(imgPath.lastIndexOf('.') + 1).toLowerCase();
        if (ext == "gif" || ext == "png" || ext == "jpg" || ext == "jpeg")
            alert("Please select image file (jpg, jpeg, png).")
    function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
//              $("#remove").val(0);
    function removeImage() {
        $('#preview').attr('src', 'noimage.jpg');
//      $("#remove").val(1);

So here we completed the tutorial on Image preview before upload with javascript & jquery step by step hope it's will help.

About Author
  • user profile
    Brijpal Sharma, January 29th, 2018

    Hello, My Name is Brijpal Sharma. I am a Web Developer, Professional Blogger and Digital Marketer from India. I am the founder of Codermen. I started this blog to help web developers & bloggers by providing easy and best tutorials, articles and offers for web developers and bloggers...

0 Comment

You must be logged in to post a comment.