Display upload progress percent in submit button

This commit is contained in:
Micah Lee 2019-02-14 09:45:41 -08:00
parent dd3f2d60b6
commit 38c39918d4
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73

View File

@ -9,8 +9,9 @@ form.onsubmit = function(event) {
event.preventDefault();
// Disable button, and update text
uploadButton.disabled = true;
uploadButton.innerHTML = 'Uploading ...';
uploadButton.disabled = true;
fileSelect.disabled = true;
// Create form data
var files = fileSelect.files;
@ -25,7 +26,7 @@ form.onsubmit = function(event) {
ajax.upload.addEventListener('progress', function(event){
console.log('upload progress', 'uploaded '+event.loaded+' bytes / '+event.total+' bytes');
var percent = Math.ceil(event.loaded / event.total) * 100;
var percent = parseInt((event.loaded / event.total) * 100, 10);
uploadButton.innerHTML = 'Uploading '+percent+'%';
}, false);
@ -35,6 +36,7 @@ form.onsubmit = function(event) {
// Re-enable button, and update text
uploadButton.innerHTML = 'Send Files';
uploadButton.disabled = false;
fileSelect.disabled = false;
}
}, false);