Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

upload file javascript mdn

function updateImageDisplay() {
  while(preview.firstChild) {
    preview.removeChild(preview.firstChild);
  }

  const curFiles = input.files;
  if(curFiles.length === 0) {
    const para = document.createElement('p');
    para.textContent = 'No files currently selected for upload';
    preview.appendChild(para);
  } else {
    const list = document.createElement('ol');
    preview.appendChild(list);

    for(const file of curFiles) {
      const listItem = document.createElement('li');
      const para = document.createElement('p');
      if(validFileType(file)) {
        para.textContent = `File name ${file.name}, file size ${returnFileSize(file.size)}.`;
        const image = document.createElement('img');
        image.src = URL.createObjectURL(file);

        listItem.appendChild(image);
        listItem.appendChild(para);
      } else {
        para.textContent = `File name ${file.name}: Not a valid file type. Update your selection.`;
        listItem.appendChild(para);
      }

      list.appendChild(listItem);
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js how to remove blue while click 
Javascript :: how to read textbox values from html and insert them into tables using java script 
Javascript :: add active class to button onclick react 
Javascript :: Cannot find module Cannot find module 
Javascript :: links 
Javascript :: error-too-many-re-renders-react-limits-the-number-of-renders-to-prevent 
Javascript :: fc calendar 
Javascript :: convert string or string array to object mongoose object id 
Javascript :: select triggers mouseleave 
Javascript :: javascript concurrency 
Javascript :: save browser password 
Javascript :: zxaas 
Javascript :: set @Output through modalref angular 
Javascript :: js get current top position event listeners 
Javascript :: How do you remove property name from this code? const foo = { name; “albert” }; 
Javascript :: get-the-current-directory-name-in-javascript 
Javascript :: module scope javascript 
Javascript :: form api 
Javascript :: send back text from get request in node.js 
Javascript :: map object keys javascript 
Javascript :: multi level route static file not found issue in express 
Javascript :: javascript filter in place algorithm 
Javascript :: on second click javascript 
Javascript :: Set object Relation with Array objects javascript 
Javascript :: tokenize javascript 
Javascript :: how to call javascript function in p tag 
Javascript :: binary function 
Javascript :: how to render req.session.name to ejs 
Javascript :: javascript get hours and minutes from date 
Javascript :: jquery remove array of classes 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =