Spaces:
Sleeping

Login / index.html
Pezh's picture
Create index.html
9cbf0d6 verified
Raw History Blame Contribute Delete
2.24 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flask App</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<label for="numberInput">Enter a number:</label>
<input type="text" id="numberInput" name="number">
<button id="sendButton">Send</button>
<input type="text" id="resultInput" name="result" readonly>
<div id="checkboxDiv">
<!-- Checkboxes will be added here by JavaScript -->
</div>
<button id="makeCheckboxButton">Make to Checkbox</button>
<script>
$(document).ready(function () {
// Handle the Send button click event
$('#sendButton').click(function () {
$.post('/multiply', {
number: $('#numberInput').val()
}, function (data) {
$('#resultInput').val(data.result);
});
});
// Handle the Make to Checkbox button click event
$('#makeCheckboxButton').click(function () {
let list = <?php echo json_encode($list_of_items) ?>;
let checkboxDiv = $('#checkboxDiv');
checkboxDiv.empty(); // Clear the div
list.forEach(function (item, index) {
// Create the checkbox for each item
let checkbox = $(`<input type="checkbox" name="items" value="${item}">`);
let label = $(`<label>${item}</label><br>`);
// Append the checkbox and label to the div
checkboxDiv.append(checkbox);
checkboxDiv.append(label);
// Handle checkbox change event to add checked items to list
checkbox.change(function () {
$.post('/check_items',
{ items: $('input[name="items"]:checked').map(function(){ return $(this).val(); }).get() },
function (data) {
console.log(data);
}
);
});
});
});
});
</script>
</body>
</html>