var files = [];
const div_files = document.getElementById("files");
const div_results = document.getElementById("results");
function fetchNames() {
div_files.innerHTML = ""; // clears the file div
div_results.innerHTML = ""; // clears the results div
var checkbox_elements = document.getElementsByClassName('filename');
Array.from(checkbox_elements).forEach(function(k) {
if (k.checked) {
files.push(k.value);
div_files.innerHTML += k.value + '<br>';
}
});
// the files array should now be shared with python
//console.log(files);
// JavaScript SHOULD WAIT while PYTHON processes the data and shares the cal_array with JS
// when the cal_array is available with JS only then it shall start processing the code mentioned below
var cal_array = [
[2231, 11640, 104621],
[2231, 11640, 104621],
[9, 494, 3339]
];
Array.from(cal_array).forEach(function(k) {
div_results.innerHTML += k + '<br>';
})
};
<form>
<input type="checkbox" class="filename" value="./first.html">First File<br>
<input type="checkbox" class="filename" value="./second.html">Second File<br>
<input type="checkbox" class="filename" value="./third.html">Third File<br>
<br>
<input type="button" value="Submit" onclick="fetchNames()">
</form>
<br>
The selected file(s) are:
<div id="files"></div>
<br> The result shows the number of lines, words, and characters of the respective files mentioned above:
<div id="results"></div>
Mads Marquart :
If what you want is to create a web-app, and then send the data from there to your server via. AJAX, where you will work on the data in Python, what you need is something like Flask.\n\nIf what you want is to create a web-app that also runs the Python code, you need a python interpreter written in JavaScript, something like pyjs",
2017-11-16T13:04:59