HTML
<form id="form_one">
<label for="pet-select">Choose a pet:</label>
<select name="param2" id="pet-select">
<option value="">--Please choose an option--</option>
<option value="dog">Dog</option>
<option value="cat">Cat</option>
<option value="hamster">Hamster</option>
<option value="parrot">Parrot</option>
<option value="spider">Spider</option>
<option value="goldfish">Goldfish</option>
</select>
<input type="hidden" value="You chose " name="param1">
<input type="submit">
</form>
<div>
<output id="selected"></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('selected').value = responseArray[0];
document.getElementById('selected').value += responseArray[1];
} catch (e) {
console.error(e);
}
}
document.getElementById('form_one').addEventListener('submit', function (event) {
event.preventDefault();
sendData();
});