Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

preview image file upload javascript

<input type="file" accept="image/*" onchange="loadFile(event)">
<img id="output"/>
<script>
  var loadFile = function(event) {
    var output = document.getElementById('output');
    output.src = URL.createObjectURL(event.target.files[0]);
    output.onload = function() {
      URL.revokeObjectURL(output.src) // free memory
    }
  };
</script>
Comment

upload preview image js

// <input type="file" accept="image/*" id="img-input">
// <img id="preview"/>
function readURL(input) {
      if (input.files && input.files[0]) {
          var reader = new FileReader();
          reader.onload = function(e) {
          $('#preview').attr('src', e.target.result);
          }
          reader.readAsDataURL(input.files[0]);
      } else {
          $('#preview').attr('src', '');
      }
    }

  $("#img-input").change(function() {
    readURL(this);
  });
Comment

Javascript Image Preview Before Upload

imgInp.onchange = evt => {
  const [file] = imgInp.files
  if (file) {
    blah.src = URL.createObjectURL(file)
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: what is middleware in express js 
Javascript :: make query param optional node 
Javascript :: skip map iteration javascript 
Javascript :: js add margin with variable 
Javascript :: javascript split multiple values 
Javascript :: all jquery selectors 
Javascript :: open bootstrap modal using vanilla js 
Javascript :: update a value from array in redux state 
Javascript :: javascript string methods cheat sheet 
Javascript :: toast show pb 
Javascript :: react createelement 
Javascript :: Format javascript date with date.js library 
Javascript :: react places autocomplete 
Javascript :: javascript append array to end of array 
Javascript :: error: Error: Unable to resolve module `crypto` from `node_modulescrypto-jscore.js`: crypto could not be found within the project. 
Javascript :: passport middleware check if authenticated 
Javascript :: can we add string and int in javascript 
Javascript :: an array of functions 
Javascript :: keyframe options 
Javascript :: how to compile typescript to javascript es6 
Javascript :: crud with firestore 
Javascript :: notify js 
Javascript :: jqvmap 
Javascript :: javascript map() method 
Javascript :: create text node in javascript 
Javascript :: fastify 
Javascript :: es6 class example 
Javascript :: update state in react 
Javascript :: regex or operator 
Javascript :: express rate limit 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =