Javascript Image Preview with File Upload Control

Javascript Comments Off on Javascript Image Preview with File Upload Control
<html>
<head>
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jquerzyui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
<script type="text/javascript">
function readURL(input)
{
      if (input.files && input.files[0])
              {
                    var reader = new FileReader();
                   reader.onload = function (e)
                                          {
                                                $('#blah')
                                                .attr('src',e.target.result)
                                                .width(150)
                                                .height(200);
                                          };
                   reader.readAsDataURL(input.files[0]);
                   }
}
</script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://goo.gl/r57ze"></script>
<![endif]-->
</head>
<body>
<input type='file' onChange="readURL(this);" />
<img id="blah" src="#" alt="Image Name" width="0" height="0" />
</body>
</html>


Author

Search

Back to Top