view raw
Edward Hasted Edward Hasted - 10 months ago 406
HTML Question

HTML - Display image after selecting filename

Possible Duplicate:

Preview an image before it is uploaded

I have a form that allows me with

<input type="file" name="filename" accept="image/gif, image/jpeg, image/png">

to browse and select a file.

What I want to do is display that image immediately after the image has been selected.
And this is before the "submit" button on the form has been pressed so the image almost certainly resides Client side. Can this be done?


Here You Go:


<!DOCTYPE html>
<link class="jsbin" href="" rel="stylesheet" type="text/css" />
<script class="jsbin" src=""></script>
<script class="jsbin" src=""></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src=""></script>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  <input type='file' onchange="readURL(this);" />
    <img id="blah" src="#" alt="your image" />


function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();

            reader.onload = function (e) {


Live Demo