'Save text to server-side file in HTML/Javascript

I'm using Bootstrap to build a small website. To narrow my question, assume that this is the only element in the entire webpage:

<!DOCTYPE html>
<html lang="en-US">

<head>
    <meta charset="UTF-8">
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <title>Webpage</title>
</head>

<body>
    <div class="shadow-lg container align-items-center rounded rounded-3 border-2 d-none d-md-block"
        style="margin-left:auto; margin-right:auto;width: 600px;justify-content:center;">
        <div class="justify-content-center d-flex pt-3">
        <p class="text-center"><strong>What brings you to my website?</strong></p>
    </div>
    <div class="justify-content-center d-flex" action="log.php" method="POST">
        <input type="text" class="form-control" id="whatBrings" style="width: 400px;" placeholder="">
    </div>
    <div class="justify-content-center d-flex">
        <div class="text-center">
        <button type="button" id="submitButton" class="btn btn-primary my-3">Submit</button>
        </div>
    </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
    integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
    crossorigin="anonymous"></script>
</body>

My JavaScript for handling the Submit button:

var submitButton = document.getElementById("submitButton");
var whatBrings = document.getElementById("whatBrings");

submitButton.addEventListener("click", function(){
    alert("Button was clicked");

    //store whatBrings.value in server-side file here

    whatBrings.value = ""; //reset text box
});

How would I store the string whatBrings.value in a server-side file? A solution in JavaScript would be preferable, but PHP would work as well.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source