Spaces:
Runtime error
Runtime error
function submitForm() { | |
var fileInput = document.getElementById('csvFile'); | |
var processingMsg = document.getElementById('processingMsg'); | |
if (fileInput.files.length === 0) { | |
alert('Please select a CSV file.'); | |
return; | |
} | |
var formData = new FormData(); | |
formData.append('csvFile', fileInput.files[0]); | |
// Show processing message | |
document.getElementById('uploadForm').classList.add('hidden'); | |
processingMsg.classList.remove('hidden'); | |
// Simulate backend processing (replace with actual AJAX call) | |
setTimeout(function() { | |
// After processing (simulated with setTimeout), show success message | |
processingMsg.innerHTML = '<p>File processed successfully. <a href="#" onclick="downloadProcessedFile()">Download processed file</a></p>'; | |
}, 2000); | |
} | |
function downloadProcessedFile() { | |
// Here you can add code to download the processed file | |
alert('Downloading processed file...'); | |
// Replace this alert with your actual download logic | |
} | |
document.getElementById('submitBtn').addEventListener('click', function() { | |
var fileInput = document.getElementById('csvFile'); | |
var file = fileInput.files[0]; | |
if (file) { | |
var formData = new FormData(); | |
formData.append('file', file); | |
// Capture checkbox values | |
var checkboxes = document.querySelectorAll('input[name="option"]:checked'); | |
checkboxes.forEach(function(checkbox) { | |
formData.append('option', checkbox.value); | |
}); | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', '/'); | |
xhr.upload.onprogress = function(event) { | |
if (event.lengthComputable) { | |
var percentComplete = (event.loaded / event.total) * 100; | |
document.getElementById('progressBar').style.width = percentComplete + '%'; | |
} | |
}; | |
xhr.onloadstart = function() { | |
document.getElementById('processingMsg').classList.remove('hidden'); | |
}; | |
xhr.onloadend = function() { | |
document.getElementById('processingMsg').classList.add('hidden'); | |
document.getElementById('downloadBtn').classList.remove('hidden'); | |
var response = JSON.parse(xhr.responseText); | |
document.getElementById('downloadBtn').addEventListener('click', function() { | |
window.location.href = '/downloads/output.xlsx'; | |
}); | |
}; | |
xhr.send(formData); | |
} | |
}); | |