I have a simple file upload js that allows me to use a stylized button rather than the traditional form element UI. It basically hides the fileElement and hooks it up to my stylized button. Issue I have now is that I am missing the traditional "name of file" that was picked.
<input type="file" class="fileElem pull-right" id="chooseFile" multiple onchange="handleFiles(this.files)">
<button class="fileSelect pull-right" id="selectFile">Choose File</button>
<script type="text/javascript">
function click(el) {
// Simulate click on the element.
var evt = document.createEvent('Event');
evt.initEvent('click', true, true);
el.dispatchEvent(evt);
}
document.querySelector('#selectFile').addEventListener('click', function(e) {
var fileInput = document.querySelector('#chooseFile');
//click(fileInput); // Simulate the click with a custom event.
fileInput.click(); // Or, use the native click() of the file input.
}, false);
function handleFiles(files) {
alert('Well done!');
}