HTML
<form id="form_one">
<fieldset>
<legend>Choose your interests</legend>
<div>
<input type="checkbox" id="coding" name="param1" value="coding" checked />
<label for="coding">Coding</label>
</div>
<div>
<input type="checkbox" id="music" name="param2" value="music" />
<label for="music">Music</label>
</div>
<div>
<input type="submit">
</div>
</fieldset>
</form>
<div>
<output id="out-choice1"></output>
<output id="out-choice2"></output>
</div>
javascript
// form
async function sendData() {
const formData = new FormData(form_one);
try {
const response = await fetch("https://php.tomgdow.com", {
method: "POST",
body: formData
});
let result = await response.text();
console.log(result);
let responseArray = result.split('&');
document.getElementById('out-choice1').value = responseArray[0];
document.getElementById('out-choice2').value = responseArray[1];
} catch (e) {
console.error(e);
}
}
document.getElementById('form_one').addEventListener('submit', function (event) {
event.preventDefault();
sendData();
});