Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

preview multiple image before upload

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="file-input" type="file" multiple>
<div id="preview"></div>
 Run code snippetHide results
Comment

preview multiple image before upload

function previewImages() {

  var $preview = $('#preview').empty();
  if (this.files) $.each(this.files, readAndPreview);

  function readAndPreview(i, file) {
    
    if (!/.(jpe?g|png|gif)$/i.test(file.name)){
      return alert(file.name +" is not an image");
    } // else...
    
    var reader = new FileReader();

    $(reader).on("load", function() {
      $preview.append($("<img/>", {src:this.result, height:100}));
    });

    reader.readAsDataURL(file);
    
  }

}

$('#file-input').on("change", previewImages);
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery autocomplete search 
Javascript :: js check if string contains character 
Javascript :: merge two strings with alternate characters javascript 
Javascript :: angular print html 
Javascript :: can we get the value of form control after disabling it angular 
Javascript :: mongoose auto increment 
Javascript :: Conditional expressions and in fandom explained examples 
Javascript :: how to convert string to toggle case in javascript 
Javascript :: jquery embeded by console 
Javascript :: jsconfig.json code to support absolute import 
Javascript :: apar chinmoy phy js code 
Javascript :: import json file into javascript 
Javascript :: recoil js 
Javascript :: shorthand if in javascript with return 
Javascript :: how to add value with useref in react 
Javascript :: regex to valied password strength stackoverflow 
Javascript :: visual studio node.js cleint missing intents error 
Javascript :: javascript delete dict value 
Javascript :: js backwards loop 
Javascript :: .change() in pure js 
Javascript :: highlight link javascript 
Javascript :: mock function jest 
Javascript :: Firebase: Error (auth/invalid-api-key). 
Javascript :: react native stack transition from right to left 
Javascript :: scrape data from ao3 
Javascript :: reac native play sound 
Javascript :: how to give index in query selector in js 
Javascript :: how to create a blob javascript 
Javascript :: change array range value javascript 
Javascript :: React Javascript Builtin Hooks Import bug 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =