JSFiddle - React, Tailwind, and code Playground

by Felipe Kautzmann

HTML

<input type='file' id='fileinput' style='display:none' />
<button onclick='document.getElementById("fileinput").click()'>SelectFile</button>

JavaScript

var fileSelectEle = document.getElementById('fileinput');

fileSelectEle.onclick = charge;

function charge()
{
    document.body.onfocus = function () { setTimeout(checkOnCancel, 100); };
}

function checkOnCancel()
{
    if(fileSelectEle.value.length == 0) alert('You clicked cancel - ' + "FileName:" + fileSelectEle.value + "; Length: " + fileSelectEle.value.length)
    else alert('You selected a file - ' + "FileName:" + fileSelectEle.value + "; Length: " + fileSelectEle.value.length);
    document.body.onfocus = null;
}