Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to display the image before uploading?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 289
    Comment on it

    Hello friends,

    Today we learn how we can display a image before uploading using jquery. For this we will take a input field of file type and a image tag as follows:

    <input type="file" id="demo" />
    <img id="demoimage" />

    After that we will write Javascript which will read the image and will dipslay it by assigning it to image tag as follows:

    document.getElementById("demo").onchange = function () {
        var reader = new FileReader();
    
        reader.onload = function (e) {
            // get loaded data and render thumbnail.
            document.getElementById("demoimage").src = e.target.result;
        };
    
        // read the image file as a data URL.
        reader.readAsDataURL(this.files[0]);
    };
    

    So this way you can simply display your image without uploading

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: