<script type="text/javascript">
myForm.addEventListener('change', myChangeHandler)
function myChangeHandler() {
const checkedInputs = myForm.querySelectorAll('input:checked')
const ids = Array.from(checkedInputs).map(inp => inp.id)
const idsListString = JSON.stringify(ids)
// display
out.textContent = idsListString
// save
localStorage.setItem('data', idsListString)
}
</script>
по подробней?
function myChangeHandler() {
const checkedInputs = myForm.querySelectorAll('input:checked');
const ids = Array.from(checkedInputs).map(inp => inp.id);
const idsListString = JSON.stringify(ids);
(async () => {
let answer = await fetch('handler.php',{
method: 'POST',
headers: {'Content-type' : 'application/x-www-form-urlencoded; charset=UTF-8'},
body: 'arrFromJS=' + idsListString // на сервере ловить $_POST['arrFromJS']
}),
data = await answer.text();
console.log(data);
})();
// display
out.textContent = idsListString
// save
localStorage.setItem('data', idsListString)
}