HTML5 <input type=“file” accept=“image/*” capture=“camera”> display as image rather than “choose file” button

JavascriptWeb DevelopmentFront End Scripts

Use the JavaScript FileReader to allow users to choose an image.

Let us see an example −

<form id = "myform" runat = "server">
   <input type = 'file' id = "myimg" />
   <img id = "myid" src = "#" alt = "new image" />
</form>

Here is the JS −

function readURL(input) {
   if (input.files && input.files[0]) {
      var r = new FileReader();
      r.onload = function (ev) {
         $('#myid).attr('src', ev.target.result);
      }
      reader.readAsDataURL(input.files[0]);
   }
}   
raja
Published on 05-Apr-2018 15:46:59
Advertisements