Simple JS Form
by Matt Tyson
HTML
<form name="myform" action="" method="GET">
Enter something in the box: <br>
<input type="text" name="inputbox" value="" />
<input type="button" name="button" value="Click" onClick="testResults(this.form)" />
<p id="result">
</p>
</form>
JavaScript
function testResults (form) {
var inputValue = form.inputbox.value;
fetch("https://echo.zuplo.io/", {
method: "POST",
body: "Very interesting: " + inputValue
})
.then((response) => response.text())
.then((responseText) => {
alert(responseText);
document.querySelector("#result").innerHTML = responseText
})
.catch((error) => {
console.error("foo: " + error)
})
}