Click here to Skip to main content
15,115,960 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
    Test = {
        UpdatePreview: function(obj){
          // if IE < 10 doesn't support FileReader
             // don't know how to proceed to assign src to image tag
          } else {
             var reader = new FileReader();
             var target = null;

             reader.onload = function(e) {
              target = || e.srcElement;
             $("#ImageId").attr("src", target.result);

my html code..............

What I have tried:

the above code is what i have try but the image is not show at all
Updated 10-Aug-20 1:24am

1 solution

Use the JavaScript readAsDataURL() Method.

Refer: How to Preview an Image Before it is Uploaded Using jQuery[^]
Here, try this:
<!DOCTYPE html>
    <html lang="en">
    <meta charset="utf-8">
    <title>jQuery Preview an Image Before it is Uploaded</title>
    <script src=""></script>

        function previewFile(input){
            var file = $("input[type=file]").get(0).files[0];
                var reader = new FileReader();
                reader.onload = function(){
                    $("#previewImg").attr("src", reader.result);
        <form action="confirmation.php" method="post">
                <input type="file" name="photo" onchange="previewFile(this);" required>
            <img id="previewImg" src="/examples/images/transparent.png" alt="Placeholder">
                <input type="submit" value="Submit">
Ibrahim Hassan 1234 9-Aug-20 15:32pm
im realy appreciate for your quick respond sir, doctor prof Sandeep Mewara.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900