HTML
<form id="form_one">
<input type="hidden" name="param1" value="Your choice is ">
<label for="ice-cream-choice">Choose a flavor:</label>
<input list="ice-cream-flavors" id="ice-cream-choice" name="param2" />
<datalist id="ice-cream-flavors">
<option value="Chocolate"></option>
<option value="Coconut"></option>
<option value="Mint"></option>
<option value="Strawberry"></option>
<option value="Vanilla"></option>
</datalist>
<input type="submit">
</form>
<output id="user_choice"></output>
Browser
JavaScript
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('user_choice').value = responseArray[0] + responseArray[1];
} catch (e) {
console.error(e);
}
}
document.getElementById('form_one').addEventListener('submit', function (event) {
event.preventDefault();
sendData();
});